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

NullnessChecker: how to disable only the Initialization checker?

我参考了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 checker: 与 AsuppressWarnings=initialization.

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

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

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

3.1 and 3.8 of the Checker Framework manual 部分建议使用 -AsuppressWarnings=uninitialized 而不是 -AsuppressWarnings=initialization。这适用于您的示例。

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