Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove incorrect handling of covariant return types #83

Merged
merged 2 commits into from
Jul 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
invoker.goals=verify
invoker.buildResult=failure
# this is where the method signature change happened
invoker.java.version = 1.9+,!16

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
File log = new File(basedir, 'build.log')
assert log.exists()
assert log.text.contains( 'ManimalSniffer49.java:51: Covariant return type change detected: java.nio.Buffer java.nio.ByteBuffer.flip() has been changed to java.nio.ByteBuffer java.nio.ByteBuffer.flip()' )
assert log.text.contains( 'ManimalSniffer49.java:76: Covariant return type change detected: java.nio.Buffer java.nio.ByteBuffer.flip() has been changed to java.nio.ByteBuffer java.nio.ByteBuffer.flip()' )
assert log.text.contains( 'ManimalSniffer49.java:51: Undefined reference: java.nio.ByteBuffer java.nio.ByteBuffer.flip()' )
assert log.text.contains( 'ManimalSniffer49.java:76: Undefined reference: java.nio.ByteBuffer java.nio.ByteBuffer.flip()' )
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,12 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.zip.GZIPInputStream;

import org.codehaus.mojo.animal_sniffer.logging.Logger;
import org.codehaus.mojo.animal_sniffer.logging.PrintWriterLogger;
import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.Attribute;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.FieldVisitor;
Expand Down Expand Up @@ -516,7 +514,7 @@ private void check( String owner, String sig, boolean ignoreError )
{
return;
}
if ( find( classes.get( owner ), sig, true ) )
if ( find( classes.get( owner ), sig ) )
{
return; // found it
}
Expand Down Expand Up @@ -553,7 +551,7 @@ private boolean shouldBeIgnored( String type, boolean ignoreError )
* If the given signature is found in the specified class, return true.
* @param baseFind TODO
*/
private boolean find( Clazz c , String sig , boolean baseFind )
private boolean find( Clazz c , String sig )
{
if ( c == null )
{
Expand All @@ -570,7 +568,7 @@ private boolean find( Clazz c , String sig , boolean baseFind )
return false;
}

if ( find( classes.get( c.getSuperClass() ), sig, false ) )
if ( find( classes.get( c.getSuperClass() ), sig ) )
{
return true;
}
Expand All @@ -579,41 +577,13 @@ private boolean find( Clazz c , String sig , boolean baseFind )
{
for ( int i = 0; i < c.getSuperInterfaces().length; i++ )
{
if ( find( classes.get( c.getSuperInterfaces()[i] ), sig, false ) )
if ( find( classes.get( c.getSuperInterfaces()[i] ), sig ) )
{
return true;
}
}
}

// This is a rare case and quite expensive, so moving it to the end of this method and only execute it from
// first find-call.
if ( baseFind )
{
// MANIMALSNIFFER-49
Pattern returnTypePattern = Pattern.compile( "(.+\\))L(.+);" );
Matcher returnTypeMatcher = returnTypePattern.matcher( sig );
if ( returnTypeMatcher.matches() )
{
String method = returnTypeMatcher.group( 1 );
String returnType = returnTypeMatcher.group( 2 );

Clazz returnClass = classes.get( returnType );

if ( returnClass != null && returnClass.getSuperClass() != null )
{
String oldSignature = method + 'L' + returnClass.getSuperClass() + ';';
if ( find( c, oldSignature, false ) )
{
logger.info( name + ( line > 0 ? ":" + line : "" )
+ ": Covariant return type change detected: "
+ toSourceForm( c.getName(), oldSignature ) + " has been changed to "
+ toSourceForm( c.getName(), sig ) );
return true;
}
}
}
}
return false;
}

Expand Down