4

I have wrote a class that implements the comparable interface. I used @NotNull annotation to suppress the waring in the method parameter. But it still shows a warning.The IDE automatically import this package com.sun.istack.internal.NotNull for the @NotNull. Why this is happing? Without using this annotation how to remove this warning ?
I am using Inteij Ultimate with java 8 SE. Here is my code snippet.enter image description here

Thank you.

seal
  • 1,122
  • 5
  • 19
  • 37
  • 1
    Try adding @Nonnull (javax.annotation.Nonnull) to the `compareTo` method. – Olivier Poulin Jul 02 '15 at 15:38
  • Correct, `javax.annotation.NonNull` is the right one. – uraimo Jul 02 '15 at 15:40
  • 1
    @uraimo I can not see any annotation like `NotNull` or `Nonnull` in the `javax.annotation` package. When i am trying to write down `javax.annotation.NotNull` or `javax.annotation.Nonnull` then a error occur. – seal Jul 02 '15 at 16:00
  • Updated my answer, sorry but this question is a bit prone to typos :) – uraimo Jul 02 '15 at 16:07

2 Answers2

5

Apparently, you should be using

public int compareTo(@NonNull Node node) {

instead of

public int compareTo(@NotNull Node node) {

The compiler can determine cases where a code path might receive a null value, without ever having to debug a NullPointerException.

From here.

For these annotations you need Checker Framework installed. Or you can try what the other answer says.

mernst
  • 7,437
  • 30
  • 45
Olivier Poulin
  • 1,778
  • 8
  • 15
  • 1
    Not an android question, even if the ide is in dark-mode :) – uraimo Jul 02 '15 at 15:46
  • 1
    @uraimo whoops, im in the wrong tag! xD I'll change it. – Olivier Poulin Jul 02 '15 at 15:47
  • @uraimo Edited definition/link to be more relevent to OP :) – Olivier Poulin Jul 02 '15 at 15:50
  • 1
    Good God... i think all permutations are actually available as real classes... NotNull, NonNull, Notnull,etc... his issues is that he didn't import one of the annotations accepted by IntelliJ. – uraimo Jul 02 '15 at 16:00
  • Sorry, but there is no such thing `Nonnull`. I also try to import `javax.annotation.` package but there is no such annotation like `Nonnull` or `NotNull`. Is there any problem with my jdk version ? I am using currently java version "1.8.0_45". – seal Jul 02 '15 at 16:04
  • Update answer, sorry. – uraimo Jul 02 '15 at 16:06
1

Change your import, you can use intellij's own com.intellij.annotations.NotNull, javax.annotation.Nonnull or javax.validation.constraints.NotNull.

This is an IntelliJ feature and it was actually possible to configure which nullable/notnull annotation to use, see this guide.

If this doesn't fix it, and the message seems to imply this, try removing the @override, you are adding an annotation to a parameter that didn't have it in the super class.

uraimo
  • 19,081
  • 8
  • 48
  • 55
  • 1
    In `javax.annotation` package there is not `@NotNull` or `@Nonnull` annotation. I have changed the configuration according to your given link but my ide still can not find those annotation in that package. – seal Jul 02 '15 at 16:42
  • [I have these annotations](http://grepcode.com/snapshot/repo1.maven.org/maven2/org.glassfish/javax.annotation/3.1) except `ManagedBean`. – seal Jul 02 '15 at 16:49