[Misc] Merge collapsible nested if statements (SonarCloud java:S1066)#5829
Open
vmassol wants to merge 1 commit into
Open
[Misc] Merge collapsible nested if statements (SonarCloud java:S1066)#5829vmassol wants to merge 1 commit into
vmassol wants to merge 1 commit into
Conversation
Mechanical, behaviour-preserving cleanup of SonarCloud rule java:S1066
("Merge this if statement with the enclosing one") across 17 modules:
22 nested if statements merged into a single condition using &&.
Co-Authored-By: Vincent Massol <vincent@massol.net>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Mechanical, behaviour-preserving cleanup of SonarCloud rule java:S1066 ("Merge this if statement with the enclosing one") across 17 modules. 23 issues fixed in 20 files.
Merging a collapsible nested
ifinto its enclosing one with&&reduces nesting and makes the combined condition explicit, without changing behaviour (&&short-circuits exactly as the nestedifs did).Details
For each flagged inner
if, the outer and inner conditions were merged with&&, the innerifline removed, the body dedented, and the redundant brace removed:if (A) { if (B) { BODY } }→if (A && B) { BODY }||were wrapped in parentheses to preserve precedence.//comment between the twoifs described the inner condition, it was moved directly above the mergedif.A number of flagged sites were intentionally left out because merging them would not be behaviour-preserving or clean: the enclosing statement is an
else if, the innerifis not the sole statement of the outer body, or a multi-line comment (or a comment documenting the outer condition) sits between the twoifs.No production behaviour changed; only control-flow structure.
All fixed issues belong to SonarCloud rule
java:S1066. See the open S1066 issues for this project.Test plan
mvn clean install -Plegacy,snapshot -DskipTestsacross all 17 affected modules in one reactor — BUILD SUCCESS. Test sources still compile and Checkstyle passes; the merges are behaviour-preserving.🤖 Generated with Claude Code