gpt4 book ai didi

java - 空值检查器 : how to disable only the Initialization checker?

转载 作者:行者123 更新时间:2023-12-02 02:37:34 26 4
gpt4 key购买 nike

我指的是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 ,但保留空检查?

最佳答案

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

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

关于java - 空值检查器 : how to disable only the Initialization checker?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46057929/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com