2

I am using IntelliJ 13.1.5 and Java 8 SDK and I've set up IntelliJ built-in nullness checker to use checkers.nullness.quals.NonNull as the annotation of my choice.

Now, when I write a simple class like this

import checkers.nullness.quals.NonNull;

public class Myclass  {
    public void doSomething(@NonNull String someString) {
    }
}

IntelliJ underlines the @NonNull annotation with the warning

Cannot annotate with both @NonNull and @NonNull

First I thought it has something to do with classes that implement interface which also have methods annotated with @NonNull.

But I also happens with concrete classes like the example above.

My next guess was that multiple libraries use the same annotation name and there might be a name clash. But unfortunately the warning doesn't specify the exact class name with packages. If this is the case, there must be some setting that enables implicit annotations.

How can I get rid of this warning without removing the annotation?

jaw
  • 932
  • 2
  • 10
  • 24

2 Answers2

2

I've just got a reply to be issue that helped me resolve the problem. I'm still not sure if this was my fault or if this is a bug, but here is the solution:

IntelliJ has (at least) two locations in the project settings where you can configure the nullness annotations which are:

  1. Settings | Inspections | Constant conditions & exceptions | Configure annotations
  2. Settings | Inspections | @NotNull/@Nullable problems | Configure annoations

When I set up the annotations, added them using 1.) not knowing there is 2.). The issue was cause because in 2.), the annotation checkers.nullness.quals.NonNull was selected in both the Nullable and NonNull sections which is obviously wrong. In 1.) everything was fine.

To resolve the issue, I removed checkers.nullness.quals.NonNull from the Nullable section in 2.) and added and selected checkers.nullness.quals.Nullable.

jaw
  • 932
  • 2
  • 10
  • 24
1

This looks like a bug in IDEA. For historical reasons, many toolkits will treat any annotations with certain simple names (like NonNull) as equivalent, and it looks like IDEA may have some collisions. You should report this as a bug to JetBrains.

chrylis -cautiouslyoptimistic-
  • 75,269
  • 21
  • 115
  • 152
  • There is an internal `NonNull` annotation in openapi (intellij core) iirc. I'm not sure if this could be where the conflict lies. – vikingsteve Oct 27 '14 at 15:10