typetools / typetools/checker-framework

We need a way to suppress all initialization errors

Open
#1,590 9 comments 7 reactions 0 assignees View on GitHub

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=uninitialized suppresses all warnings related to initialization itself. It lets you write a constructor that does not initialize all its fields, for example.
The -AsuppressWarnings=uninitialized affects messages that are printed as initialization errors but not errors that are printed as other types.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.