Bug: Merging if Statements with SonarLint changes semantics

Hello everybody,

I just happened to notice a bug when using SonarLint in IntelliJ. Given the following Java-Code, Sonar Lint suggests to merge the two if statements:

if (a || b) {
    if (c) {
        // code
    }
}

However, the result of this action changes the semantics of the if statement:

if (a || b && (c)) {
    // code
}

When merging the two if statements with native IntelliJ Feature “merge nested if statements” the result is correct:

if ((a || b) && c) {
    // code
}

My expectation would be, that the SonarLint Plugin would behave the same way (or even use the same functions under the hood) as IntelliJ when merging the if statements to not change the semantics and introduce a new bug.

SonarLint PluginVersion: 10.3.0.77475
IntelliJ Version: Build #IU-233.14015.106
Platform: MacOS

2 Likes

Hello @ben.ne, and welcome to the Sonar Community!

Thank you for reporting this bug in the quick fix for S1066. The [SONARJAVA-4873] - Jira has been created to address it.

Cheers,
Angelo

Thanks, Angelo!
You’re welcome, nice to hear this is beeing adressed! :slight_smile:

2 Likes