Skip to content

Commit

Permalink
Remove incorrect handling of covariant return types (#83)
Browse files Browse the repository at this point in the history
* Remove incorrect handling of covariant return types

* update integration test expectations
  • Loading branch information
ogolberg committed Jul 25, 2021
1 parent f8df3fe commit ba0d71e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 36 deletions.
@@ -1,4 +1,5 @@
invoker.goals=verify
invoker.buildResult=failure
# this is where the method signature change happened
invoker.java.version = 1.9+,!16

@@ -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()' )
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

0 comments on commit ba0d71e

Please sign in to comment.