Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java compilation error using findbugs. com.sun.tools.javac.code.Symbol$CompletionFailure: class file for javax.annotation.meta.When not found

Tags:

java

findbugs

I am trying to use the annotations of findbugs 1.3.2.

I used the edu.umd.cs.findbugs.annotations.NonNull annotation in a simple test, and it works fine.

However, now I have a large project, composed of sub-modules, using maven, and I get the following compilation error by just importing that annotation in some java file:

com.sun.tools.javac.code.Symbol$CompletionFailure: class file for javax.annotation.meta.When not found

what can be the problem? i tried adding the findbugs dependency in all sub-modules. maybe it is a conflict with jsr305? I see that one of our dependencies uses jsr305 1.3.9.

like image 526
David Portabella Avatar asked Jun 19 '12 15:06

David Portabella


2 Answers

In my experience, this error always occurs when you use @NonNull and jsr305.jar is not on the classpath. In order to use the findbugs annotations, you must add both annotations.jar and jsr305.jar to the classpath.
Some annotations (I am thinking of @SuppressWarnings) can be used without jsr305.jar, but @NonNull requires it for sure.

(You mentioned jsr305.jar in your question, but you didn't say explicitly that you've checked. Also, people are going to land here when searching for the error message, and they will need to add jsr305.jar.) Only one version of jsr305.jar should be on the classpath.

like image 120
barfuin Avatar answered Oct 20 '22 12:10

barfuin


You can also use this dependency

    <dependency>
        <groupId>com.google.code.findbugs</groupId>
        <artifactId>annotations</artifactId>
        <version>3.0.1</version>
    </dependency>
like image 23
red Avatar answered Oct 20 '22 13:10

red