David Portabella
David Portabella

Reputation: 12720

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

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.

Upvotes: 8

Views: 10722

Answers (2)

barfuin
barfuin

Reputation: 17494

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.

Upvotes: 8

red
red

Reputation: 916

You can also use this dependency

    <dependency>
        <groupId>com.google.code.findbugs</groupId>
        <artifactId>annotations</artifactId>
        <version>3.0.1</version>
    </dependency>

Upvotes: 3

Related Questions