NullnessChecker: how to disable only the Initialization checker?

假装没事ソ 提交于 2019-12-12 04:08:32

问题


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:


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.



来源:https://stackoverflow.com/questions/46057929/nullnesschecker-how-to-disable-only-the-initialization-checker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!