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

Merging of nested ifs not always correct #631

Open
Luro02 opened this issue Oct 23, 2024 · 0 comments
Open

Merging of nested ifs not always correct #631

Luro02 opened this issue Oct 23, 2024 · 0 comments
Labels
bug Something isn't working false-positive A lint triggers on something that is correct. high-priority Issues that should be solved as soon as possible

Comments

@Luro02
Copy link
Collaborator

Luro02 commented Oct 23, 2024

Summary

For the below code, it seems to suggest merging the nested if with the outer one through &&, even though that is not applicable.

Lint Name

ChainedIfCheck

Reproducer

if (a <= 0) {
    if (a == -3) {
        System.out.println("a is -3");
    }
    return;
}

if (a == 1) {
    if (b == 2) {
        System.out.println("a is 1");
    }
} else if (a == 2) {
    if (b == 3) {
        throw new IllegalStateException("an error occurred");
    }
    System.out.println("a is 2");
} else if (a == 3) {
    if (b == 3) {
        System.out.println("a is 3 and b is 3");
    } else {
        throw new IllegalStateException("should never happen");
    }
}

and

if (a == 2) {
    if (b == 2) {
        throw new IllegalStateException("an error occurred");
    }
    System.out.println("a is 2, b is not 2");
}
@Luro02 Luro02 added bug Something isn't working false-positive A lint triggers on something that is correct. high-priority Issues that should be solved as soon as possible labels Oct 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working false-positive A lint triggers on something that is correct. high-priority Issues that should be solved as soon as possible
Projects
None yet
Development

No branches or pull requests

1 participant