Skip to content

[Misc] Merge collapsible nested if statements (SonarCloud java:S1066)#5829

Open
vmassol wants to merge 1 commit into
masterfrom
claude/vigilant-dirac-sryqex
Open

[Misc] Merge collapsible nested if statements (SonarCloud java:S1066)#5829
vmassol wants to merge 1 commit into
masterfrom
claude/vigilant-dirac-sryqex

Conversation

@vmassol

@vmassol vmassol commented Jul 13, 2026

Copy link
Copy Markdown
Member

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 if into its enclosing one with && reduces nesting and makes the combined condition explicit, without changing behaviour (&& short-circuits exactly as the nested ifs did).

Details

For each flagged inner if, the outer and inner conditions were merged with &&, the inner if line removed, the body dedented, and the redundant brace removed:

  • if (A) { if (B) { BODY } }if (A && B) { BODY }
  • Operands containing a top-level || were wrapped in parentheses to preserve precedence.
  • Where a single-line // comment between the two ifs described the inner condition, it was moved directly above the merged if.
  • A few merged conditions were wrapped onto two lines with a +4 continuation indent to stay within the 120-character line limit.

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 inner if is not the sole statement of the outer body, or a multi-line comment (or a comment documenting the outer condition) sits between the two ifs.

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 -DskipTests across 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

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>
@vmassol vmassol added the llm-agent To be used for PRs created autonomously by LLM agents. label Jul 13, 2026 — with Claude
@vmassol vmassol self-assigned this Jul 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

llm-agent To be used for PRs created autonomously by LLM agents.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant