checker framework, is there any way to silence/disable type.anno.before.modifier warning?

590 Views Asked by At

I thought I'd give checker framework a go, but I'm getting a lot of this

/Users/calebcushing/IdeaProjects/ppm/scaf/src/main/java/com/xenoterracide/scaf/Config.java:22: warning: [type.anno.before.modifier] write type annotation @NonNull() immediately before type, after modifiers [abstract]
  abstract Map<String, SkeletonConfiguration> getTemplates();

for this code

  @Nullable
  abstract String getWorkdir();

it seems to be suggestion that I should write

  abstract @Nullable String getWorkdir();

but that goes against the JLS, is there anyway to disable this?

2

There are 2 best solutions below

2
On BEST ANSWER
  1. You said, "that goes against the JLS", but it does not. It's legal Java, and it is better style.

  2. The Checker Framework Manual describes how to suppress warnings, for example via the @SuppressWarning("type.anno.before.modifier") annotation or the -AsuppressWarnings=type.anno.before.modifier command-line argument.

0
On

but that goes against the JLS

Answering purely for this statement: checker is implementing what is described in JLS 9.7.4:

It is customary, though not required, to write declaration annotations before all other modifiers, and type annotations immediately before the type to which they apply.

As indicated in the Javadoc of Checker's Nullable:

Nullable is a type annotation

hence it should appear immediately before the type to which it applies, namely, the method's return type.


You also linked JLS 8.4.3 in a comment. This shows the grammar production MethodModifier:

MethodModifier:
    (one of)
    Annotation public protected private
    abstract static final synchronized native strictfp

This isn't directly relevant: for one thing, it says you can only use one of these modifiers, so it can't tell you anything about ordering. But if you check JLS 19, you can find the context in which MethodModifier appears:

MethodDeclaration:
    {MethodModifier} MethodHeader MethodBody

MethodModifier:
    (one of)
    Annotation public protected private
    abstract static final synchronized native strictfp

MethodHeader:
    Result MethodDeclarator [Throws]
    TypeParameters {Annotation} Result MethodDeclarator [Throws]

So, checker is telling you to put the annotation as specified in the MethodHeader production.