Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliJ suggests wrong @NotNull annotation

IntelliJ is suggesting to import com.sun.istack.internal.NotNull the @NotNull annotation (which is wrong) in the following program:

public class Test implements Comparable<Test> {
    @Override
    public int compareTo(@NotNull Test o) {
        return 0;
    }
}

When trying the correct import com.intellij.annotations.NotNull (I think) it looks like it can't find the class:

enter image description here

like image 270
traveh Avatar asked Jul 06 '15 10:07

traveh


3 Answers

You can Alt+Enter on the warning before you add the annotation, press Right, choose Edit Inspection Settings, then Configure Annotations and specify the annotation you want to be inserted there.

like image 79
Peter Gromov Avatar answered Sep 17 '22 14:09

Peter Gromov


Remove the import from the code. IntelliJ will ask you to import it again. It should suggest that there are multiple choices available. The annotation you want should be in the list.

like image 43
duffymo Avatar answered Sep 18 '22 14:09

duffymo


I found I had to add the following dependency declaration to my Java project's build.gradle file before I was able to import the org.jetbrains.annotations.NotNull and org.jetbrains.annotations.Nullable annotations rather than the com.sun.istack.internal.NotNull and com.sun.istack.internal.Nullable annotations:

repositories {
    mavenCentral()
}

dependencies {
    compile 'org.jetbrains:annotations:15.0'
}
like image 27
Adil Hussain Avatar answered Sep 20 '22 14:09

Adil Hussain