typetools / typetools/checker-framework
We need a way to suppress all initialization errors
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 1.1k
- Forks
- 440
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 134
Description
We need a way to suppress all initialization errors (but not the nullness checks).
Example:
public final class InitTest {
private String field;
public InitTest() {
init();
}
private void init() {
field = "";
}
}
The initialization checker of the checker-framework correctly reports the issues:
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
According to the docs of the Initialization Checker, it should be able to disable the initialization checker via a command line argument:
To disable initialization checking, supply the command-line argument
-AsuppressWarnings=uninitialized
When we use this argument (in checker-framework 2.2.1) we still get an initialization error:
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
Quote from mernst in this Stackoverflow discussion "How to suppress all initialization errors" :
-AsuppressWarnings=uninitializedsuppresses all warnings related to initialization itself. It lets you write a constructor that does not initialize all its fields, for example.
The-AsuppressWarnings=uninitializedaffects messages that are printed as initialization errors but not errors that are printed as other types.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the InitTest example with checker-framework 2.2.1 and -AsuppressWarnings=uninitialized, then trace how the initialization checker handles initialization.fields.uninitialized versus method.invocation.invalid. Check the Initialization Checker documentation and existing suppression tests first. Done means initialization errors are suppressible without suppressing the nullness checks, with a regression test for this example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- compilers, devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100