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

2

8

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.

Magpie answered 19/6, 2012 at 15:48 Comment(2)
you are getting class not found exception. check the java build path if the concerned jars are added by maven.Notability
yes, the maven dependency tree shows that findbugs is included in the classpath.Magpie
S
8

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.

Semiliterate answered 19/10, 2012 at 12:54 Comment(2)
Worked like a charm. Added this to my pom and now the compiler is happy: <dependency> <groupId>com.google.code.findbugs</groupId> <artifactId>jsr305</artifactId> <version>2.0.3</version> </dependency>Chervonets
Added as a Gradle dependency: implementation("com.google.code.findbugs:annotations:3.0.1") implementation("com.google.code.findbugs:jsr305:3.0.2") Still the same problem, didn't solve the issue.Cao
S
3

You can also use this dependency

    <dependency>
        <groupId>com.google.code.findbugs</groupId>
        <artifactId>annotations</artifactId>
        <version>3.0.1</version>
    </dependency>
Slim answered 14/5, 2019 at 18:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.