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

False positive on variable populated in exhaustive switch expression #1124

Open
wbadam opened this issue Jan 6, 2025 · 1 comment
Open

Comments

@wbadam
Copy link

wbadam commented Jan 6, 2025

Starting from version 0.11.0, NullAway reports false positive on a nullable variable after the switch expression:

    public enum SomeEnum {
        A,
        B,
    }

    public int exhaustiveSwitch(SomeEnum e) {
        String s = null;
        switch (e) {
            case A -> {
                s = "A";
            }
            case B -> throw new RuntimeException();
        }
        return s.length(); // <-- warning: [NullAway] dereferenced expression s is @Nullable
    }

Runnable example

s at the return statement is non-nullable because the exhaustive switch either sets a value or makes the line unreachable.

Version 0.10.26 didn't report this warning.

@msridhar
Copy link
Collaborator

msridhar commented Jan 6, 2025

I can reproduce. Thanks for the report. I'll have to dig a bit deeper to understand what is going on here.

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

No branches or pull requests

2 participants