NullnessChecker: how to disable only the Initialization checker?

928 views Asked by At

I refer to the nullness-example in the docs (checker-framework version: 2.1.14)

When I run the example as recommended to check NullnessExampleWithWarnings.java:

javac -processor org.checkerframework.checker.nullness.NullnessChecker docs/examples/NullnessExampleWithWarnings.java

I get the expected errors:

..\..\docs\examples\NullnessExampleWithWarnings.java:23: error: [assignment.type.incompatible] incompatible types in assignment.
        foo = bar;
              ^
  found   : @FBCBottom @Nullable String
  required: @UnknownInitialization @NonNull String
..\..\docs\examples\NullnessExampleWithWarnings.java:33: error: [argument.type.incompatible] incompatible types in argument.
        foo.add(quux);
                ^
  found   : @FBCBottom @Nullable String
  required: @Initialized @NonNull String
2 errors

Now I disable the Initialization checker: with AsuppressWarnings=initialization.

javac -processor org.checkerframework.checker.nullness.NullnessChecker -AsuppressWarnings=initialization docs/examples/NullnessExampleWithWarnings.java

But this also disables the null-checks and the build does not report anymore errors.

How can I disable the Initialization checker, but keep the Null-checks?

1

There are 1 answers

0
mernst On BEST ANSWER

Sections 3.1 and 3.8 of the Checker Framework manual suggest using -AsuppressWarnings=uninitialized rather than -AsuppressWarnings=initialization. That works for your example.

The reason for that recommendation is an implementation detail of the Nullness and Initialization Checkers: they are actually the same checker, rather than being two separate checkers that are aggregated together.