Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the error message of initialization checker by showing the uninitialized fields #622

Open
Ao-senXiong opened this issue Nov 21, 2023 · 3 comments · May be fixed by #623
Open

Improve the error message of initialization checker by showing the uninitialized fields #622

Ao-senXiong opened this issue Nov 21, 2023 · 3 comments · May be fixed by #623
Assignees

Comments

@Ao-senXiong
Copy link
Member

The issue is from #621.

When the initialization checker issues errors related to uninitialized fields, it would be helpful if it could also indicate which specific fields have not been initialized.

@Ao-senXiong
Copy link
Member Author

@wmdietl I think right now we do show the uninitialized fields in the error message. See the following example:

class Demo {
    String s;
    Object foo;

    Demo() {
        init();
    }

    void init() {}
}

Command : java -jar checker/dist/checker.jar -processor nullness FinalClass.java
Error message:

FinalClass.java:5: error: [initialization.fields.uninitialized] the constructor does not initialize fields: s, foo
    Demo() {
    ^
FinalClass.java:6: error: [method.invocation.invalid] call to init() not allowed on the given receiver.
        init();
            ^
  found   : @UnderInitialization Demo
  required: @Initialized Demo
2 errors

@wmdietl
Copy link
Member

wmdietl commented Nov 21, 2023

Try the following changed constructor:

    Demo() {
        s = "";
        init();
        foo = "";
    }

@Ao-senXiong
Copy link
Member Author

Great! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants