當我有一個簡單的測試類如何抑制所有初始化錯誤
public final class InitTest {
private String field;
public InitTest() {
init();
}
private void init() {
field = "";
}
}
檢驗器框架的初始化檢查正確報告的問題:
InitTest.java:7: error: [initialization.fields.uninitialized] the constructor does not initialize fields: field
public InitTest() {
^
InitTest.java:8: error: [method.invocation.invalid] call to init() not allowed on the given receiver.
init();
^
found : @UnderInitialization(java.lang.Object.class) @NonNull InitTest
required: @Initialized @NonNull InitTest
2 errors
按照docs of the Initialization Checker,它應該能夠通過命令行參數禁用初始化檢查程序:
To disable initialization checking, supply the command-line argument
-AsuppressWarnings=uninitialized
當我們使用該參數(在檢查框架2.2.1),我們仍然可以獲得一個初始化錯誤:
InitTest.java:8: error: [method.invocation.invalid] call to init() not allowed on the given receiver.
init();
^
found : @UnderInitialization(java.lang.Object.class) @NonNull InitTest
required: @Initialized @NonNull InitTest
1 error
我缺少的東西,或這是一個錯誤?
注意:當我們使用-AsuppressWarnings=initialization
時,不再顯示任何錯誤 - 但這也會抑制與nullness相關的問題:請參閱此SO discussion。
這裏是相關的[issue 1590](https://github.com/typetools/checker-framework/issues/1590) – TmTron