javaannotationsnullpointerexceptionnullablenull-pointer

Can't find @Nullable inside javax.annotation.*


I want use @Nullable annotation to eliminate NullPointerExceptions. I found some tutorials on the net, I noticed that this annotation comes from the package javax.annotation.Nullable; but when I import it a compilation error is generated: cannot find symbol


Solution

  • You need to include a jar that this class exists in. You can find it here

    If using Maven, you can add the following dependency declaration:

    <dependency>
      <groupId>com.google.code.findbugs</groupId>
      <artifactId>jsr305</artifactId>
      <version>3.0.2</version>
    </dependency>
    

    and for Gradle:

    dependencies {
      testImplementation 'com.google.code.findbugs:jsr305:3.0.2'
    }