Giter VIP home page Giter VIP logo

animal-sniffer's People

Contributors

aheritier avatar csoroiu avatar cstamas avatar davidkarlsen avatar dependabot[bot] avatar diogoteles08 avatar don-vip avatar famod avatar finomosec avatar godin avatar hboutemy avatar jessefarinacci avatar jglick avatar johnou avatar jtnord avatar kohsuke avatar lzaruba avatar marcono1234 avatar mfriedenhagen avatar ogolberg avatar olamy avatar rfscholte avatar rhowe avatar slachiewicz avatar slawekjaranowski avatar stephenc avatar steven-sheehy avatar tchemit avatar uweplonus avatar yschimke avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

animal-sniffer's Issues

in JDK5 forbidden @override is not detected

This code, which is not good for JDK5, is not detected by animal sniffer:

private static final Comparator<? extends Comparable> OBJCOMP = new Comparator<Comparable>()
{
    @Override
    public int compare(Comparable object1, Comparable object2)
    {
        return object1.compareTo(object2);
    }
};

The "@OverRide" is not allowed here, because it isn't allowed for the implementation of interfaces in JDK5. (But allowed in JDK6)

Source retention

The animal sniffer annotations, specifically @IgnoreJRERequirement, are set to CLASS retention. Should this instead be SOURCE? Is there a reason they need to be retained in the .class file but not loaded by the VM?

Perhaps animal sniffer itself checks the .class files rather than the .java files?

Animal Sniffer Signature Error

I'm using a dependency which uses Animal Sniffer and getting errors, the dependency i'm using is:

<dependency>
			<groupId>org.apache.jena</groupId>
			<artifactId>jena-tdb</artifactId>
			<version>3.2.0</version>
		</dependency>

when doing a mvn clean install , i'm getting the following error:

Failed to execute goal org.codehaus.mojo:animal-sniffer-maven-plugin:1.11:check (signature-check) on project frontend-core: Execution signature-check of goal org.codehaus.mojo:animal-sniffer-maven-plugin:1.11:check failed. IllegalArgumentException -> [Help 1]

when using the Maven Debug with the command mvn -X -Dmaven.test.skip=true clean install, i get the following

[ERROR] Failed to execute goal org.codehaus.mojo:animal-sniffer-maven-plugin:1.11:check (signature-check) on project frontend-core: Execution signature-check of goal org.codehaus.mojo:animal-sniffer-maven-plugin:1.11:check failed. IllegalArgumentException -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:animal-sniffer-maven-plugin:1.11:check (signature-check) on project frontend-core: Execution signature-check of goal org.codehaus.mojo:animal-sniffer-maven-plugin:1.11:check failed.
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
	at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
	at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
	at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
	at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
	at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
	at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
	at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution signature-check of goal org.codehaus.mojo:animal-sniffer-maven-plugin:1.11:check failed.
	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:145)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
	... 20 more
Caused by: java.lang.IllegalArgumentException
	at org.objectweb.asm.ClassReader.<init>(Unknown Source)
	at org.objectweb.asm.ClassReader.<init>(Unknown Source)
	at org.objectweb.asm.ClassReader.<init>(Unknown Source)
	at org.codehaus.mojo.animal_sniffer.ClassListBuilder.process(ClassListBuilder.java:71)
	at org.codehaus.mojo.animal_sniffer.ClassFileVisitor.processJarFile(ClassFileVisitor.java:157)
	at org.codehaus.mojo.animal_sniffer.ClassFileVisitor.process(ClassFileVisitor.java:107)
	at org.codehaus.mojo.animal_sniffer.maven.CheckSignatureMojo.apply(CheckSignatureMojo.java:235)
	at org.codehaus.mojo.animal_sniffer.maven.CheckSignatureMojo.buildPackageList(CheckSignatureMojo.java:221)
	at org.codehaus.mojo.animal_sniffer.maven.CheckSignatureMojo.execute(CheckSignatureMojo.java:162)
	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
	... 21 more

Allow users to invoke animal-sniffer from the Maven command line

People who manage large code-bases or build systems sometimes do not have direct access to the underlying POMs. One way of adding important checks such as API compatibility is to invoke the tools directly from the command line, with the configuration specified at the same time.

Animal-sniffer doesn't currently allow users to specify the API signature on the command line, which means it cannot be run without modifications to the POM.

I've filed PR #2 to add the appropriate Mojo goodness.

Support setting classes directory on check goal

I'm trying to generate a jar with retrolambda that it's backwards compatible to Java 6, and using animal sniffer to check that Java 7 API isn't being using. The problem is that I setup retrolambda and maven-jar.plugin to use a different class directory, animal sniffer checks against Java 6 the class files for Java 6 AND Java 7. I need to control that checks only against the Java 6 class files.

Allowing that check goal uses classesDirectory parameter would do the trick.

Question about ignoreDependencies and setCheckJars

I can't make the maven plugin check dependencies. I have tried both "true" and "false" forignoredependencies. Looking at the source code I think the line signatureChecker.setCheckJars(false) prevents the plugin from checking dependencies.

Version 1.17 is not compatible with java 8

Version 1.17 is compiled with java 9 (Build-Jdk: 9.0.4) which has breaking api changes.

I faced problem here (in context of ant task):

Caused by: java.lang.NoSuchMethodError: java.nio.CharBuffer.position(I)Ljava/nio/CharBuffer;
	at org.codehaus.mojo.animal_sniffer.SignatureChecker.toSourceType(SignatureChecker.java:639)
	at org.codehaus.mojo.animal_sniffer.SignatureChecker.toSourceForm(SignatureChecker.java:595)
	at org.codehaus.mojo.animal_sniffer.SignatureChecker$CheckingVisitor.error(SignatureChecker.java:565)
	at org.codehaus.mojo.animal_sniffer.SignatureChecker$CheckingVisitor.access$800(SignatureChecker.java:282)
	at org.codehaus.mojo.animal_sniffer.SignatureChecker$CheckingVisitor$1.check(SignatureChecker.java:463)
	at org.codehaus.mojo.animal_sniffer.SignatureChecker$CheckingVisitor$1.visitMethodInsn(SignatureChecker.java:398)
	at org.codehaus.mojo.animal_sniffer.asm.shaded.ClassReader.readCode(ClassReader.java:2211)
	at org.codehaus.mojo.animal_sniffer.asm.shaded.ClassReader.readMethod(ClassReader.java:1274)
	at org.codehaus.mojo.animal_sniffer.asm.shaded.ClassReader.accept(ClassReader.java:679)
	at org.codehaus.mojo.animal_sniffer.asm.shaded.ClassReader.accept(ClassReader.java:391)
	at org.codehaus.mojo.animal_sniffer.SignatureChecker.process(SignatureChecker.java:197)
	at org.codehaus.mojo.animal_sniffer.ClassFileVisitor.processClassFile(ClassFileVisitor.java:198)
	at org.codehaus.mojo.animal_sniffer.ClassFileVisitor.process(ClassFileVisitor.java:116)
	at org.codehaus.mojo.animal_sniffer.ant.CheckSignatureTask.execute(CheckSignatureTask.java:210)
	at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293)
	at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
	... 59 more

In java 8 .position(int) method was in Buffer, but in java 9 new method was added directly to CharBuffer

If 1.17 is supposed to be used only with java 9 (or above) please mention it somewhere. For now, It looks like it was supposed to be working on 1.7 and above

Possible fixes:

  • ((Buffer)type).position( i + 1 ) (workaround, could break in other places)
  • --release 7 compiler flag. This way compatibility should be granted.

Support skipping specified classes when performing checking

Is it possible to have a new <configuration> parameter where we could specify classes/dependencies to skip over when performing the checking.

For my use case, there are entire classes I want skipped when checking for signatures. Rather than having to annotate all the individual methods, it would be nice to have a <configuration> parameter that can define the behavior.

Animal sniffer 1.14 doesn't detect java version

When I specify 1.8 for the Java version used by my project to compile sources, animal sniffer doesn't detect that the java version isn't compatible with Java 1.6, the version checked by animal sniffer.

This is my configuration:

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>animal-sniffer-maven-plugin</artifactId>
  <version>1.14</version>
  <configuration>
    <signature>
      <groupId>org.codehaus.mojo.signature</groupId>
      <artifactId>java16</artifactId>
      <version>1.0</version>
    </signature>
  </configuration>
  <executions>
    <execution>
      <id>ensure-java-1.6-class-library</id>
      <phase>test</phase>
      <goals>
        <goal>check</goal>
      </goals>
    </execution>
  </executions>
</plugin>

But when I use a version before 1.14, I got an IllegalArgumentException from animal sniffer and the execution of the plugin stop the execution of my project. This is what I want (I would like more info about what doesn't work but this is a good start).

java 1.8 as minimum

because we are in mid 2018 so it's time to get rid of java 1.7 support :)

Bad class file

Hi.

I'm getting a Bad class file error when compiling and running with Java 9.0.1 on Travis or Running Java 10.0.1. Similarly, it happens with Java 9.0.4 on my local machine.

Versions:
ru.vyarus:gradle-animalsniffer-plugin:1.4.3
animal-sniffer 1.16
gradle 4.7

[Unrecognized error] Bad class file 
c:\...\RxJava2_9\build\classes\java\jmh\io\reactivex\BlockingGetPerf.class

BlockingGetPerf.zip

This started happening after I upgraded from the plugin version 1.2.0 (which I believe run 1.15).

I know that in theory, Java 9+ have their own sniffer, but the library in question is cross-compiled to many JDK versions and compile targets to make sure both the library and the JDKs are okay.

Please advise.

NPE from CheckSignatureMojo.execute

I am getting

java.lang.NullPointerException
	at org.codehaus.mojo.animal_sniffer.maven.CheckSignatureMojo.execute(CheckSignatureMojo.java:211)
	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:132)

when trying to run Animal Sniffer on a new project, even though (AFAIK) I have no improper APIs being used.

Here is the faulty line of code:

match = findMatchingDependency( signature, project.getDependencyManagement().getDependencies() );

Effective POM excerpt:

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>animal-sniffer-maven-plugin</artifactId>
  <version>1.15</version>
  <executions>
    <execution>
      <id>check</id>
      <goals>
        <goal>check</goal>
      </goals>
      <configuration>
        <signature>
          <groupId>org.codehaus.mojo.signature</groupId>
          <artifactId>java17</artifactId>
        </signature>
      </configuration>
    </execution>
  </executions>
  <configuration>
    <signature>
      <groupId>org.codehaus.mojo.signature</groupId>
      <artifactId>java17</artifactId>
    </signature>
  </configuration>
</plugin>

ClassCastException: Cannot merger

When creating a signature, if you have two classes with the same name (e.g. in two different jars), the build-signatures rule fails with an error like the following:

build.xml:29: java.lang.ClassCastException: Cannot merger class javax/xml/xpath/XPathFactoryFinder$1 as it has changed superclass: at org.codehaus.mojo.animal_sniffer.Clazz.<init>(Clazz.java:94) at org.codehaus.mojo.animal_sniffer.SignatureBuilder$SignatureVisitor.end(SignatureBuilder.java:222) at org.codehaus.mojo.animal_sniffer.SignatureBuilder.process(SignatureBuilder.java:194) at org.codehaus.mojo.animal_sniffer.ClassFileVisitor.processJarFile(ClassFileVisitor.java:153) at org.codehaus.mojo.animal_sniffer.ClassFileVisitor.process(ClassFileVisitor.java:105) at org.codehaus.mojo.animal_sniffer.ant.BuildSignaturesTask.process(BuildSignaturesTask.java:173) at org.codehaus.mojo.animal_sniffer.ant.BuildSignaturesTask.execute(BuildSignaturesTask.java:157) at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293) at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106) at org.apache.tools.ant.Task.perform(Task.java:348) at org.apache.tools.ant.Target.execute(Target.java:435) at org.apache.tools.ant.Target.performTasks(Target.java:456) at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1405) at org.apache.tools.ant.Project.executeTarget(Project.java:1376) at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41) at org.apache.tools.ant.Project.executeTargets(Project.java:1260) at org.apache.tools.ant.Main.runBuild(Main.java:854) at org.apache.tools.ant.Main.startAnt(Main.java:236) at org.apache.tools.ant.launch.Launcher.run(Launcher.java:285) at org.apache.tools.ant.launch.Launcher.main(Launcher.java:112)

I tried to work around this by excluding all anonymous classes, but it looks like excludes aren't processed until the very end.

  1. This error probably shouldn't be fatal.
  2. I'm not convinced the error even makes sense. I don't think the superclass actually changed. As far as I can tell, both versions extend Object.
  3. Excludes should, perhaps, be checked earlier.
  4. All anonymous classes should probably be excluded by default, too. They can't reasonably be part of an API,

IllegalArgumentException in asm ClassReader constructor

Using ru.vyarus:gradle-animalsniffer-plugin:1.5.0, there's an exception caused by ASM. The classfile itself is fine, it's ASM that has the issue I think.

โฑ java -version
openjdk version "1.8.0_222"
OpenJDK Runtime Environment (build 1.8.0_222-8u222-b10-1ubuntu1~19.04.1-b10)
OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode

๎‚ฐ 09:47:51 AM | +36 ๎‚ฐ  ๎‚ฐ terse-logback ๎‚ฐ G: ๎‚  remove-kordamp ๎‚ฐ ๎‚ฐ โญ‘ ? ๎‚ฐ
โฑ ./gradlew clean  ':logback-honeycomb-playws_2.12:animalsnifferTest' --stacktrace

> Configure project :
  Building version '0.13.6' (value loaded from 'version.properties' file).

> Task :logback-honeycomb-playws_2.12:animalsnifferTest FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':logback-honeycomb-playws_2.12:animalsnifferTest'.
> Failed to check signatures

* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.

[...]

Caused by: java.io.IOException: Bad class file /home/wsargent/.gradle/caches/modules-2/files-2.1/com.typesafe.akka/akka-stream_2.12/2.5.24/8dc25d3fa49607872a55de093351210bfde0f291/akka-stream_2.12-2.5.24.jar:akka/stream/javadsl/JavaFlowSupport.class
        at org.codehaus.mojo.animal_sniffer.ClassListBuilder.process(ClassListBuilder.java:91)
        at org.codehaus.mojo.animal_sniffer.ClassFileVisitor.processJarFile(ClassFileVisitor.java:175)
        ... 118 more
Caused by: java.lang.IllegalArgumentException
        at org.codehaus.mojo.animal_sniffer.asm.shaded.ClassReader.<init>(Unknown Source)
        at org.codehaus.mojo.animal_sniffer.asm.shaded.ClassReader.<init>(Unknown Source)
        at org.codehaus.mojo.animal_sniffer.asm.shaded.ClassReader.<init>(Unknown Source)
        at org.codehaus.mojo.animal_sniffer.ClassListBuilder.process(ClassListBuilder.java:69)
        ... 119 more

Fail to detect exception class in try catch block

I spotted 2 issues with try...catch blocks.
As a context i am using master version and the java15/java16 as signatures.

  1. First is related to the fact that animal-sniffer is not reporting an exception class not available in java < 1.7. There should be an error reported on line 5, as java.lang.ReflectiveOperationException is not present in java 5 & 6 for the code below.
public void exceptionClassNotAvailableInJava6() {
    try {
        Method method = TestClass.class.getDeclaredMethod("emptyMethod");
        method.invoke(null);
    } catch (ReflectiveOperationException exception) {
        logException(exception);
    }
}
  1. The second is a little bit trickier. The effect of the below multi-catch statement is that the runtime type of the exception variable, when compiled with java7 or 8, is java.lang.ReflectiveOperationException and the frame that is generated contains java.lang.ReflectiveOperationException on the stack. Same as above, there should be an error reported on line 5, as java.lang.ReflectiveOperationException is not present in java 5 & 6 for the code below. That particular exception was added in the middle of the hierarchy in Java 7.
public void exceptionMultiCatch() {
    try {
        Method method = TestClass.class.getDeclaredMethod("emptyMethod");
        method.invoke(null);
    } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException exception) {
        logException(exception);
    }
}

Both code block from above pass the check even if they should not.
I'll post a PR soon on this matter.

Support checking of test classes

Our problem (see at https://issues.apache.org/jira/browse/PDFBOX-2891) is that we'd like test classes to be checked too. This was proposed before:
http://mojo.10943.n7.nabble.com/Fwd-animal-sniffer-for-maven-test-classes-td43156.html
I don't know if "binkley" ever followed up on his patch proposal. I built the plugin locally and used this pom:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>animal-sniffer-maven-plugin</artifactId>
    <version>1.15-SNAPSHOT</version>
    <executions>
        <execution>
            <id>check-java-version</id>
            <phase>test</phase>
            <goals>
                <goal>check</goal>
            </goals>
            <configuration>
                <signature>
                    <groupId>org.codehaus.mojo.signature</groupId>
                    <artifactId>java15</artifactId>
                    <version>1.0</version>
                </signature>
            </configuration>
        </execution>
    </executions>
</plugin>

Here's the "bad" code:

package animalsnifferdemo;

import org.junit.Test;

public class MainTest
{
    @Test
    public void testMain()
    {
        String str = "huhu";
        boolean empty = str.isEmpty();
        System.out.println(empty);
    }
}

The error (the use of isEmpty() which is not supported by JDK5) was not detected.

java lang model SourceVersion variables not checked

    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>animal-sniffer-maven-plugin</artifactId>
        <version>1.17</version>
        <executions>
            <execution>
                <id>verify-java-api</id>
                <goals>
                    <goal>check</goal>
                </goals>
                <phase>verify</phase>
            </execution>
        </executions>
        <configuration>
            <signature>
                <groupId>org.codehaus.mojo.signature</groupId>
                <artifactId>java18</artifactId>
                <version>1.0</version>
            </signature>
        </configuration>
    </plugin>

That maven configuration does not detect:

@SupportedSourceVersion(SourceVersion.RELEASE_10)

where RELEASE_10 variable definitely is not part of Java 8 API.

Call to inherited method that is not part of signature is not detected

Animal Sniffer 1.16 misses a call to an inherited method that is not part of the specified signature. Consider the following example:

package com.example;

public class ExampleClassLoader extends ClassLoader {

	@Override
	public Class<?> loadClass(String name) throws ClassNotFoundException {
		synchronized(getClassLoadingLock(name)) {
			return super.loadClass(name);
		}
	}

}

getClassLoadingLock(String) was added in Java 7. My expectation is that Animal Sniffer will report an error when checking against the Java 6 signature. The actual behaviour is that no error is reported. Please note that an error is reported if the call to getClassLoadingLock(String) is explicit about it calling a method on the super class:

package com.example;

public class ExampleClassLoader extends ClassLoader {

	@Override
	public Class<?> loadClass(String name) throws ClassNotFoundException {
		synchronized(super.getClassLoadingLock(name)) {
			return super.loadClass(name);
		}
	}

}

Here's a complete sample that reproduces the problem.

Animal Sniffer is missing proper support for @PolymorphicSignature methods (such as MethodHandles.invoke)

For the code

AccessibleObject field = /* ... */;

MethodHandle isAccessible =
        MethodHandles.lookup().findVirtual(AccessibleObject.class, "isAccessible",
            MethodType.methodType(boolean.class));

accessible.set((Boolean) isAccessible.invokeExact(field));

I get the following for org.codehaus.mojo.signature:java17:1.0:

[ERROR] Undefined reference: Boolean java.lang.invoke.MethodHandle.invokeExact(java.lang.reflect.AccessibleObject)

However this method is defined in JDK 1.7:

https://docs.oracle.com/javase/7/docs/api/java/lang/invoke/MethodHandle.html#invokeExact(java.lang.Object...)

MethodHandle::invoke is also missing from the java17 signatures (and maybe other things).

NPE from CheckSignatureRule.apply

The execution of the enforcer plugin failed due to artifact.getFile being NULL in CheckSignatureRule.apply:

Caused by: java.lang.NullPointerException
        at org.codehaus.mojo.animal_sniffer.ClassFileVisitor.process(ClassFileVisitor.java:95)
        at org.codehaus.mojo.animal_sniffer.enforcer.CheckSignatureRule.apply(CheckSignatureRule.java:335)
        at org.codehaus.mojo.animal_sniffer.enforcer.CheckSignatureRule.buildPackageList(CheckSignatureRule.java:282)
        at org.codehaus.mojo.animal_sniffer.enforcer.CheckSignatureRule.execute(CheckSignatureRule.java:178)
        at org.apache.maven.plugins.enforcer.EnforceMojo.execute(EnforceMojo.java:193)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
        ... 21 more

It seems that Maven's Artifact.getFile can be NULL in cases when dependencies haven't been completely resolved yet.

Animal Sniffer: 1.14
Maven: 3.3.3

Unable to auto-detect boot classpath for JDK 9

Creating a api signature for JDK 9 fails because the animal sniffer plugin can't detect the boot classpath for JDK 9.

I took the following steps:

I downloaded the JDK 9 from http://www.java.net/download/java/jdk9/archive/157/binaries/jdk-9-ea+157_linux-x64_bin.tar.gz to "/usr/lib/jvm/java-9-jdk".

I configured the following toolchain in the "~/.m2/toolchains.xml":

<toolchain> <type>jdk</type> <provides> <version>1.9</version> <vendor>oracle</vendor> </provides> <configuration> <jdkHome>/usr/lib/jvm/java-9-jdk</jdkHome> </configuration> </toolchain>

If configured the animal sniffer plugin as follows:
<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>animal-sniffer-maven-plugin</artifactId> <executions> <execution> <id>create-signature</id> <phase>package</phase> <goals> <goal>build</goal> </goals> <configuration> <includeModuleClasses>false</includeModuleClasses> <includeJavaHome>true</includeJavaHome> <jdk> <version>1.9</version> </jdk> </configuration> </execution> </executions> </plugin>

After executing "mvn clean verify" I got the following error message:

[ERROR] Failed to execute goal org.codehaus.mojo:animal-sniffer-maven-plugin:1.15:build (create-signature) on project jdk9-signature: Could not auto-detect java boot classpath for /usr/lib/jvm/java-9-jdk/bin/java -> [Help 1] org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:animal-sniffer-maven-plugin:1.15:build (create-signature) on project jdk9-signature: Could not auto-detect java boot classpath for /usr/lib/jvm/java-9-jdk/bin/java at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80) at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51) at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128) at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307) at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193) at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106) at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863) at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288) at org.apache.maven.cli.MavenCli.main(MavenCli.java:199) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289) at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415) at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356) Caused by: org.apache.maven.plugin.MojoFailureException: Could not auto-detect java boot classpath for /usr/lib/jvm/java-9-jdk/bin/java at org.codehaus.mojo.animal_sniffer.maven.BuildSignaturesMojo.detectJavaClasspath(BuildSignaturesMojo.java:483) at org.codehaus.mojo.animal_sniffer.maven.BuildSignaturesMojo.detectJavaBootClasspath(BuildSignaturesMojo.java:447) at org.codehaus.mojo.animal_sniffer.maven.BuildSignaturesMojo.execute(BuildSignaturesMojo.java:340) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207) ... 20 more

I could also recreate the error by executing:

/usr/lib/jvm/java-9-jdk/jre/bin/java -jar [...]/java-boot-classpath-detector-1.15.jar

Which fails withe the following error message:

Cannot auto-detect boot class path 9-ea [...]/java-boot-classpath-detector-1.15.jar

Cannot check signatures against non-Java-Platform APIs

The documentation claims you can generate signatures of other APIs. I just tried to do so, for javax.servlet:servlet-api:2.4. It did not work. If I build

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>โ€ฆ</groupId>
    <artifactId>โ€ฆ</artifactId>
    <version>โ€ฆ</version>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <dependencies>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.4</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>animal-sniffer-maven-plugin</artifactId>
                <version>1.15</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>build</goal>
                        </goals>
                        <configuration>
                            <includeJavaHome>false</includeJavaHome>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

then I get a reasonable-looking artifact. But if I try to then use it

<execution>
  <goals>
    <goal>check</goal>
  </goals>
  <id>check-servlet</id>
  <configuration>
    <signature>
      <groupId>โ€ฆ</groupId>
      <artifactId>โ€ฆ</artifactId>
      <version>โ€ฆ</version>
    </signature>
  </configuration>
</execution>

I get numerous errors:

/โ€ฆ/src/main/java/โ€ฆ.java:โ€ฆ: Undefined reference: Object

Now the documentation does say

in general the Java Runtime signatures should form part of your API's signatures

I do not really want to do thisโ€”I am already checking a Java Platform signature separately, and in this check I only want to check Servlet API class usagesโ€”but fine, I will include the Java 8 Platform in my signature. Yet when I go to do this

you can base your API off an existing Java Runtime signature

the documentation refers to

<includeSignatures>

which does not exist. (The coordinate org.codehaus.mojo.animal_sniffer:java:1.0:java-1.4-generic is wrong too, by the way; I think you meant org.codehaus.mojo.signature:java15:1.0?)

<includeDependencies>
    <dependency>javax.servlet:servlet-api</dependency>
</includeDependencies>

at check time does not help.

If I give up on referring to a known Java Platform artifact and just delete

<configuration>
    <includeJavaHome>false</includeJavaHome>
</configuration>

then (even though I am running Maven with โ€ฆ/jdk8/bin/java) I get an error

Cannot include java home if java home is not specified (either via javaClassPath, javaHome or jdk)

referring to a nonexistent parameter javaClassPath; I suppose javaHomeClassPath was meant. I need to pass

-DjavaHome=/โ€ฆ/jdk8

to the mvn command to build the signature. But now when I run the check goal against this, it passes even if I have deliberately inserted a call to HttpServletResponse.getStatus() into my sources, which was a method added in 3.0.

Unsupported Type as a return type or field is not recoagnized (mojo)

Hi,

following example passes java17 check:

public class IllegalTypeReturn {

    public LocalDateTime localDateTime() {
        return null;
    }

}

The return statement gets examined, but it is ignored due to the Mojo adding all classes to ignoredPackages. The return type of the method signature is not checked at all.

Similarily following code passes the check for java17:

public class IllegalFieldSample {

    private String stringField;
    private LocalDateTime localDateTimeField;

}

Fields are not examined at all, and while there is no manipulation (calls) to the fields, it passes.

I will attach a pull request with a proposed solution to both of the issues shortly.

Undefined reference: java.util.concurrent.ConcurrentHashMap.KeySetView java.util.concurrent.ConcurrentHashMap.keySet()

Followup to #8:
With the project https://github.com/aclemons/animal-sniffer-npe and usage of 1.15-SNAPSHOT the NPE is solved but a new issue comes up: animal-sniffer-npe/src/main/java/nz/caffe/sniffer/NullPointerAnimalSniffer.java:30: Undefined reference: java.util.concurrent.ConcurrentHashMap.KeySetView java.util.concurrent.ConcurrentHashMap.keySet()

This isn't true and the signature error doesn't get raised if mvn is started with jre 1.7 but if mvn is started with jre 1.8 the check doesn't work correct.

Are there plans for a java18 org.codehaus.mojo.signature artifact?

My project is in the process of setting the baseline Java version to 1.8. We use the animal-sniffer plugin to ensure API compatibility and I was not able to find a java18 org.codehaus.mojo.signature artifact on maven central. I had a couple of questions:

  • Am I looking in the wrong place for the java18 signature artifact? Has the groupId changed from org.codehaus.mojo.signature?
  • Are there plans for a java18 signature that we will should make use of going forward? (note: animal sniffer checks can be disabled in our builds or we can generate a java18 signature for use locally, but we'd use the officially blessed java18 signature from maven central if available)

Thanks. Very useful plugin.

exception org.codehaus.plexus.configuration.PlexusConfigurationException is never thrown in body of corresponding try statement

[INFO] --- maven-compiler-plugin:3.6.1:compile (default-compile) @ animal-sniffer-maven-plugin ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 7 source files to /home/builder/rpmbuild/BUILD/animal-sniffer-animal-sniffer-parent-1.14/animal-sniffer-maven-plugin/target/classes
[INFO] /home/builder/rpmbuild/BUILD/animal-sniffer-animal-sniffer-parent-1.14/animal-sniffer-maven-plugin/src/main/java/org/codehaus/mojo/animal_sniffer/maven/Signature.java: Some input files use or override a deprecated API.
[INFO] /home/builder/rpmbuild/BUILD/animal-sniffer-animal-sniffer-parent-1.14/animal-sniffer-maven-plugin/src/main/java/org/codehaus/mojo/animal_sniffer/maven/Signature.java: Recompile with -Xlint:deprecation for details.
[INFO] /home/builder/rpmbuild/BUILD/animal-sniffer-animal-sniffer-parent-1.14/animal-sniffer-maven-plugin/src/main/java/org/codehaus/mojo/animal_sniffer/maven/BuildSignaturesMojo.java: Some input files use unchecked or unsafe operations.
[INFO] /home/builder/rpmbuild/BUILD/animal-sniffer-animal-sniffer-parent-1.14/animal-sniffer-maven-plugin/src/main/java/org/codehaus/mojo/animal_sniffer/maven/BuildSignaturesMojo.java: Recompile with -Xlint:unchecked for details.
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /home/builder/rpmbuild/BUILD/animal-sniffer-animal-sniffer-parent-1.14/animal-sniffer-maven-plugin/src/main/java/org/codehaus/mojo/animal_sniffer/maven/JdkToolchainConverter.java:[83,13] exception org.codehaus.plexus.configuration.PlexusConfigurationException is never thrown in body of corresponding try statement
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Skipping Animal Sniffer
[INFO] This project has been banned from the build due to previous failures.
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] 
[INFO] Animal Sniffer ..................................... SUCCESS [  0.001 s]
[INFO] Java boot classpath detector ....................... SUCCESS [  1.180 s]
[INFO] Animal Sniffer Annotations ......................... SUCCESS [  0.220 s]
[INFO] Animal Sniffer ..................................... SUCCESS [  0.881 s]
[INFO] Animal Sniffer Maven Plugin ........................ FAILURE [  1.342 s]
[INFO] Animal Sniffer Maven Enforcer Rule ................. SKIPPED
[INFO] Animal Sniffer Ant Tasks ........................... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.312 s
[INFO] Finished at: 2017-05-08T07:27:19+02:00
[INFO] Final Memory: 35M/320M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.6.1:compile (default-compile) on project animal-sniffer-maven-plugin: Compilation failure
[ERROR] /home/builder/rpmbuild/BUILD/animal-sniffer-animal-sniffer-parent-1.14/animal-sniffer-maven-plugin/src/main/java/org/codehaus/mojo/animal_sniffer/maven/JdkToolchainConverter.java:[83,13] exception org.codehaus.plexus.configuration.PlexusConfigurationException is never thrown in body of corresponding try statement
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
[ERROR] 
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <goals> -rf :animal-sniffer-maven-plugin

plexus-component-api-1.0-0.22.alpha15.fc26.noarch
plexus-containers-container-default-1.7.1-2.fc26.noarch
What other information do we need to debug further?

Failed to generate java-signatures by 'jdk'

It is said in the link https://github.com/mojohaus/animal-sniffer/blob/master/animal-sniffer-maven-plugin/src/site/apt/examples/generating-java-signatures.apt.vm

An example of using the <<>> parameter is:

 <configuration>
          ...
          <jdk>
            <version>[1.6.0,1.6.1)</version>
            <vendor>sun</vendor>
          </jdk>
          ...
        </configuration>

Issue is found

$ mvn clean compile -Dmaven.test.skip=true --global-toolchains ./toolchains.xml 
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building fpc Maven Webapp 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ fpc ---
[INFO] Deleting /home/bzu/project/new/FortiPortal/fortipmc/target
[INFO] 
[INFO] --- maven-toolchains-plugin:1.1:toolchain (default) @ fpc ---
[INFO] Required toolchain: jdk [ vendor='sun' version='8' ]
[INFO] Found matching toolchain for type jdk: JDK[/usr/lib/jvm/java8]
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ fpc ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 154 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.2:compile (default-compile) @ fpc ---
[INFO] Toolchain in compiler-plugin: JDK[/usr/lib/jvm/java8]
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 907 source files to /home/bzu/project/new/FortiPortal/fortipmc/target/classes
[INFO] 
[INFO] --- animal-sniffer-maven-plugin:1.9:check (ensure-java-8-class-library) @ fpc ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 11.673 s
[INFO] Finished at: 2017-09-02T23:42:30-07:00
[INFO] Final Memory: 18M/425M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:animal-sniffer-maven-plugin:1.9:check (ensure-java-8-class-library) on project fpc: The parameters 'signature' for goal org.codehaus.mojo:animal-sniffer-maven-plugin:1.9:check are missing or invalid -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginParameterException

My pom.xml

...
<plugins>
		<plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-toolchains-plugin</artifactId>
			<version>1.1</version>
			<configuration>
				<toolchains>
					<jdk>
						<version>${jdk.sun.specified.version}</version>
						<vendor>sun</vendor>
					</jdk>
				</toolchains>
			</configuration>
			<executions>
				<execution>
					<goals>
						<goal>toolchain</goal>
					</goals>
				</execution>
			</executions>
		</plugin>
		<plugin>
			<groupId>org.codehaus.mojo</groupId>
			<artifactId>animal-sniffer-maven-plugin</artifactId>
			<version>1.9</version>
			<configuration>
				<jdk>
					<version>${jdk.sun.specified.version}</version>
					<vendor>sun</vendor>
				</jdk>
			</configuration>
			<executions>
				<execution>
					<id> ensure-java-${jdk.sun.specified.version}-class-library</id>
					<phase>compile</phase>
					<goals>
						<goal>check</goal>
					</goals>
				</execution>
			</executions>
		</plugin>
	</plugins>
</build>
</project>

We can see the maven compiler can aware the JDK specified by toolchain plugin.
But animal sniff plugin failed .
Please let me know if I lost something to configure.
Thank you!

"Covariant return type change detected" on discarded return value

Given the code:

ByteBuffer byteBuf = getByteBuf();
byteBuf.position(offset);

Animal Sniffer reports:

Covariant return type change detected: java.nio.Buffer java.nio.ByteBuffer.position(int) has been changed to java.nio.ByteBuffer java.nio.ByteBuffer.position(int)

This is not a helpful warning, especially as the return value is discarded :-)

anima-sniffer 1.6 does not detect Closeable usage of Socket

if you have code like

Socket s = ...
closeQuietly(s);

closeQuietly(Closeable c) { c.close() }

animal-sniffer will not complain, but at runtime you will get "java.lang.IncompatibleClassChangeError"

That is because in 1.6 Socket (and ServerSocket) did not implement Closeable.

Should this be in the scope of what animal sniffer can detect?

Unhelpful error message when using X509CRL.verify(java.security.PublicKey, java.security.Provider) in project intended for jdk 1.7

jdk version: 1.8.0_192

Build error message with animal-sniffer 1.17:

Failed to execute goal org.codehaus.mojo:animal-sniffer-maven-plugin:1.17:check (check-java-version) on project AnimalSnifferBug: Execution check-java-version of goal org.codehaus.mojo:animal-sniffer-maven-plugin:1.17:check failed: An API incompatibility was encountered while executing org.codehaus.mojo:animal-sniffer-maven-plugin:1.17:check: java.lang.NoSuchMethodError: java.nio.CharBuffer.position(I)Ljava/nio/CharBuffer;

Build error message with animal-sniffer 1.16:

Undefined reference: void java.security.cert.X509CRL.verify(java.security.PublicKey, java.security.Provider)

The 1.16 error message is helpful and correct. The 1.17 error message isn't.

(Passing a java.security.Provider object to X509CRL.verify() isn't available in 1.7, only in 1.8, although 1.7 allows a String)

public class AnimalSnifferBug
{
    public static void main(String[] args) throws Exception
    {
        try (InputStream crlStream = new URL("http://crl.quovadisglobal.com/qvicag3.crl").openStream())
        {
            X509CRL crl = (X509CRL) CertificateFactory.getInstance("X.509").generateCRL(crlStream);
            crl.verify(null, new BouncyCastleProvider());
        }        
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>acme.tilman</groupId>
    <artifactId>AnimalSnifferBug</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.7</maven.compiler.source>
        <maven.compiler.target>1.7</maven.compiler.target>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.bouncycastle</groupId>
            <artifactId>bcprov-jdk15on</artifactId>
            <version>1.60</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>animal-sniffer-maven-plugin</artifactId>
                <version>1.17</version>
                <executions>
                    <execution>
                        <id>check-java-version</id>
                        <phase>test</phase>
                        <goals>
                            <goal>check</goal>
                        </goals>
                        <configuration>
                            <signature>
                                <groupId>org.codehaus.mojo.signature</groupId>
                                <artifactId>java17</artifactId>
                                <version>1.0</version>
                            </signature>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

Animal sniffer doesn't handle change in `ByteBuffer.flip` method for Java 9

While testing building various open source projects against the latest build of the Java 9, it appears that animal sniffer doesn't like the change to the Buffer.flip method on the Buffer subclasses and instead reports the following error (these errors were reported while building Maven):

[ERROR] .../maven/maven-compat/src/main/java/org/apache/maven/repository/legacy/DefaultUpdateCheckManager.java:253: Undefined reference: java.nio.ByteBuffer java.nio.ByteBuffer.flip()
[ERROR] .../maven/maven-compat/src/main/java/org/apache/maven/repository/legacy/DefaultUpdateCheckManager.java:278: Undefined reference: java.nio.ByteBuffer java.nio.ByteBuffer.flip()

The details of the changes to the API is that the on all subclasses of Buffer, the flip method will return the subclass rather than Buffer (so ByteBuffer.flip will return ByteBuffer rather than Buffer)

Fail to detect usage of unsupported type as inner class implementation

We are using Animal Sniffer on the Spring Framework to check that we don't use any Java7 or 8 API in our code base (except in specific areas that are guarded). A recent contribution uses java.util.function.Function and did not report any specific issue (while it should have).

Here is a sample that illustrates the problem:

public class Whatever {
    @UsesJava8
    private static class FunctionFoo {
        public static void foo() {
            Function<Object, Object> f = new MyFunc();
            f.apply(null);
        }

    }

    private static class MyFunc implements Function<Object,Object> {
        @Override
        public Object apply(Object o) {
            return null;
        }
    }
}

@UsesJava8 is our special marker to flag an exception. If I remove that annotation, animal sniffer reports an error on f.apply(null):

[ant:animalSniffer] /Users/snicoll/workspace/pivotal/spring-framework/spring-beans/build/classes/main/org/springframework/beans/Whatever$FunctioFoo.class:1065: Undefined reference: Object java.util.function.Function.apply(Object)

But the MyFunc is left unnoticed while it's using Function. Did I overlooked something? Thanks!

Fail to detect usage of unsupported when used as method references

I am using animal-sniffer-maven-plugin version 1.15 with java17 signature.
I have the following method:

public <T> void foo() {
    com.acme.Function<Optional<T>, T> v = Optional::get;
}

com.acme.Function does not extend java.util.function.Function.
the Optional from Optional::get method reference does not get detected.

But, when converting the method reference to a lambda, detection works fine:

public <T> void bar() {
    com.acme.Function<Optional<T>, T> v = o -> o.get();
}

As far as I can tell, the MethodVisitor returned by SignatureChecker.visitMethod method should override the MethodVisitor.visitInvokeDynamicInsn method.

NPE from SignatureChecker$CheckingVisitor.find

1.14 throws this error on my code:

java.lang.NullPointerException
    at org.codehaus.mojo.animal_sniffer.SignatureChecker$CheckingVisitor.find(SignatureChecker.java:502)
    at org.codehaus.mojo.animal_sniffer.SignatureChecker$CheckingVisitor.access$900(SignatureChecker.java:280)
    at org.codehaus.mojo.animal_sniffer.SignatureChecker$CheckingVisitor$1.check(SignatureChecker.java:416)
    at org.codehaus.mojo.animal_sniffer.SignatureChecker$CheckingVisitor$1.visitMethodInsn(SignatureChecker.java:377)
    at org.objectweb.asm.ClassReader.a(Unknown Source)
    at org.objectweb.asm.ClassReader.b(Unknown Source)
    at org.objectweb.asm.ClassReader.accept(Unknown Source)
    at org.objectweb.asm.ClassReader.accept(Unknown Source)
    at org.codehaus.mojo.animal_sniffer.SignatureChecker.process(SignatureChecker.java:195)
    at org.codehaus.mojo.animal_sniffer.ClassFileVisitor.processClassFile(ClassFileVisitor.java:176)
    at org.codehaus.mojo.animal_sniffer.ClassFileVisitor.process(ClassFileVisitor.java:101)
    at org.codehaus.mojo.animal_sniffer.ClassFileVisitor.process(ClassFileVisitor.java:81)
    at org.codehaus.mojo.animal_sniffer.ClassFileVisitor.processDirectory(ClassFileVisitor.java:119)
    at org.codehaus.mojo.animal_sniffer.ClassFileVisitor.process(ClassFileVisitor.java:97)
    at org.codehaus.mojo.animal_sniffer.ClassFileVisitor.process(ClassFileVisitor.java:81)
    at org.codehaus.mojo.animal_sniffer.ClassFileVisitor.processDirectory(ClassFileVisitor.java:119)
    at org.codehaus.mojo.animal_sniffer.ClassFileVisitor.process(ClassFileVisitor.java:97)
    at org.codehaus.mojo.animal_sniffer.ClassFileVisitor.process(ClassFileVisitor.java:81)
    at org.codehaus.mojo.animal_sniffer.ClassFileVisitor.processDirectory(ClassFileVisitor.java:119)
    at org.codehaus.mojo.animal_sniffer.ClassFileVisitor.process(ClassFileVisitor.java:97)
    at org.codehaus.mojo.animal_sniffer.ClassFileVisitor.process(ClassFileVisitor.java:81)
    at org.codehaus.mojo.animal_sniffer.ClassFileVisitor.processDirectory(ClassFileVisitor.java:119)
    at org.codehaus.mojo.animal_sniffer.ClassFileVisitor.process(ClassFileVisitor.java:97)
    at org.codehaus.mojo.animal_sniffer.ClassFileVisitor.process(ClassFileVisitor.java:81)
    at org.codehaus.mojo.animal_sniffer.ClassFileVisitor.processDirectory(ClassFileVisitor.java:119)
    at org.codehaus.mojo.animal_sniffer.ClassFileVisitor.process(ClassFileVisitor.java:97)
    at org.codehaus.mojo.animal_sniffer.ClassFileVisitor.process(ClassFileVisitor.java:81)
    at org.codehaus.mojo.animal_sniffer.ClassFileVisitor.processDirectory(ClassFileVisitor.java:119)
    at org.codehaus.mojo.animal_sniffer.ClassFileVisitor.process(ClassFileVisitor.java:97)
    at org.codehaus.mojo.animal_sniffer.maven.CheckSignatureMojo.execute(CheckSignatureMojo.java:238)

Here it seems returnClass is null.

Presumably introduced by 7349c84 (MANIMALSNIFFER-49 by @rfscholte). 1.13 works.

Animal-sniffer fails to detect Spliterator is missing from Java-1.7 signatures

When building the ClassGraph project, Animal Sniffer fails to detect that Spliterator is not part of the Java 1.7 API, using the java17 signatures:

classgraph/classgraph#363

When building, this is what I see:

[INFO] --- maven-enforcer-plugin:3.0.0-M2:enforce (check-signatures) @ classgraph ---
[INFO] Checking unresolved references to org.codehaus.mojo.signature:java17:1.0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS

CheckSignatureRule: ignoreDependencies seems inverted

Default is true which (in my project) yields many many warnings like:

[WARNING] Skipping classes in artifact commons-discovery:commons-discovery:jar:0.4 as there are unresolved dependencies.
[WARNING] Skipping classes in artifact org.jvnet:tiger-types:jar:2.2 as there are unresolved dependencies.
[WARNING] Skipping classes in artifact org.kohsuke:asm5:jar:5.0.1 as there are unresolved dependencies.

The warnings vanish once I set <ignoreDependencies>false</ignoreDependencies> which is not what I expected after reading the documentation of this flag.
See also: https://github.com/mojohaus/animal-sniffer/blob/animal-sniffer-parent-1.18/animal-sniffer-enforcer-rule/src/main/java/org/codehaus/mojo/animal_sniffer/enforcer/CheckSignatureRule.java#L290

failed to process jar: Bad class file

Seen on this PR

square/okhttp#5525

$ ./gradlew :okhttp:animalsnifferMain --stacktrace
...
Caused by: java.io.IOException:  failed to process jar /Users/yuri/.gradle/caches/modules-2/files-2.1/org.robolectric/android-all/Q-robolectric-5415296/675f28b006b4836563afee8d2f8468fece4d5bd7/android-all-Q-robolectric-5415296.jar : Bad class file /Users/yuri/.gradle/caches/modules-2/files-2.1/org.robolectric/android-all/Q-robolectric-5415296/675f28b006b4836563afee8d2f8468fece4d5bd7/android-all-Q-robolectric-5415296.jar:libcore/io/Os.class
	at org.codehaus.mojo.animal_sniffer.ClassFileVisitor.processJarFile(ClassFileVisitor.java:185)
	at org.codehaus.mojo.animal_sniffer.ClassFileVisitor.process(ClassFileVisitor.java:120)
	at org.codehaus.mojo.animal_sniffer.ant.CheckSignatureTask.apply(CheckSignatureTask.java:272)
	at org.codehaus.mojo.animal_sniffer.ant.CheckSignatureTask.buildPackageList(CheckSignatureTask.java:246)
	at org.codehaus.mojo.animal_sniffer.ant.CheckSignatureTask.execute(CheckSignatureTask.java:166)
	... 119 more
Caused by: java.io.IOException: Bad class file /Users/yuri/.gradle/caches/modules-2/files-2.1/org.robolectric/android-all/Q-robolectric-5415296/675f28b006b4836563afee8d2f8468fece4d5bd7/android-all-Q-robolectric-5415296.jar:libcore/io/Os.class
	at org.codehaus.mojo.animal_sniffer.ClassListBuilder.process(ClassListBuilder.java:91)
	at org.codehaus.mojo.animal_sniffer.ClassFileVisitor.processJarFile(ClassFileVisitor.java:175)
	... 123 more
Caused by: java.lang.IllegalArgumentException
	at org.codehaus.mojo.animal_sniffer.asm.shaded.ClassReader.<init>(Unknown Source)
	at org.codehaus.mojo.animal_sniffer.asm.shaded.ClassReader.<init>(Unknown Source)
	at org.codehaus.mojo.animal_sniffer.asm.shaded.ClassReader.<init>(Unknown Source)
	at org.codehaus.mojo.animal_sniffer.ClassListBuilder.process(ClassListBuilder.java:69)
	... 124 more

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.