NullnessChecker:如何只禁用初始化检查器?

时间:2017-09-05 14:51:58

标签: java checker-framework

我指的是nullness-example in the docs(检查框架版本:2.1.14

当我按照建议运行示例来检查NullnessExampleWithWarnings.java时:

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

我收到了预期的错误:

..\..\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

现在我停用了Initialization checkerAsuppressWarnings=initialization

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

但是这也禁用了空检查,并且构建不再报告错误。

如何禁用Initialization checker,但保留空检查?

1 个答案:

答案 0 :(得分:1)

3.13.8Checker Framework manual部分建议使用-AsuppressWarnings=uninitialized而不是-AsuppressWarnings=initialization。这适用于你的例子。

该建议的原因是Nullness和Initialization Checkers的实现细节:它们实际上是相同的检查器,而不是两个单独聚合在一起的检查器。