Skip to content

SONARJAVA-6866 Fix S9358: Move conditional expressions inside operations - #6053

Merged
romainbrenguier merged 1 commit into
masterfrom
romain/fix-qg
Aug 27, 2026
Merged

SONARJAVA-6866 Fix S9358: Move conditional expressions inside operations#6053
romainbrenguier merged 1 commit into
masterfrom
romain/fix-qg

Conversation

@romainbrenguier

@romainbrenguier romainbrenguier commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Move ternary expressions inside the common operation they feed, fixing 5 S9358 violations:
    • AssertThrowsInsteadOfTryCatchFailCheck: move ternary inside Replacements constructor (2 occurrences)
    • AndroidMobileDatabaseEncryptionKeysCheck: move ternary inside arguments.get() call
    • JParser: inline ternary into firstTokenAfter() and extract shared boolean to avoid duplicate e.isUpperBound() calls (2 occurrences)

Test plan

  • AssertThrowsInsteadOfTryCatchFailCheckTest passes
  • AndroidMobileDatabaseEncryptionKeysCheckTest passes
  • JParserTest passes

🤖 Generated with Claude Code


Summary by Gitar

  • Code improvements:
    • Refactored HashCodeMismatchedFieldsCheck to use early continue statements for cleaner loop structure
    • Removed nested conditional checks in LocalVariablesShouldNotSpanSwitchCaseGroupsCheck using early return

This will update automatically on new commits.

@hashicorp-vault-sonar-prod hashicorp-vault-sonar-prod Bot changed the title Fix S9358: Move conditional expressions inside operations SONARJAVA-6866 Fix S9358: Move conditional expressions inside operations Aug 27, 2026
@hashicorp-vault-sonar-prod

hashicorp-vault-sonar-prod Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

SONARJAVA-6866

- AssertThrowsInsteadOfTryCatchFailCheck: move ternary inside
  Replacements constructor instead of duplicating it
- AndroidMobileDatabaseEncryptionKeysCheck: move ternary inside
  arguments.get() call
- JParser: inline ternary into firstTokenAfter() call and extract
  shared boolean to avoid duplicate e.isUpperBound() calls

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@romainbrenguier
romainbrenguier marked this pull request as ready for review August 27, 2026 15:21
@gitar-bot

gitar-bot Bot commented Aug 27, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 1 resolved / 1 findings

Moves conditional expressions inside operations to fix S9358 violations across multiple check classes, addressing the branch reintroduces continue statements it set out to remove finding. All tests pass successfully.

✅ 1 resolved
Quality: Branch reintroduces continue statements it set out to remove

📄 java-checks/src/main/java/org/sonar/java/checks/HashCodeMismatchedFieldsCheck.java:120-131 📄 java-checks/src/main/java/org/sonar/java/checks/HashCodeMismatchedFieldsCheck.java:141-150 📄 java-checks/src/main/java/org/sonar/java/checks/LocalVariablesShouldNotSpanSwitchCaseGroupsCheck.java:52-61
The net branch diff (15adb94..HEAD) converts nested-if loop bodies into if (...) { continue; } in HashCodeMismatchedFieldsCheck (two loops) and LocalVariablesShouldNotSpanSwitchCaseGroupsCheck — the exact pattern commits 680c546 ("S909: Remove continue statements") and 1fbbe55 explicitly aimed to eliminate, and these two files are not mentioned in the PR description (which lists only AssertThrowsInsteadOfTryCatchFailCheck, AndroidMobileDatabaseEncryptionKeysCheck and JParser). Since this PR's purpose is clearing quality-gate issues, these changed lines will be analyzed as new code and re-raise S909, so the change works against its own goal. Behaviour is unchanged (I verified the pattern-variable flow scoping compiles and the branch logic is equivalent), so this is cosmetic: either restore the master nested-if form in both files or drop them from the PR.

Options

Auto-apply is off → Gitar will not commit updates to this branch.
Display: compact → Showing less information.

Comment with these commands to change the behavior for this request:

Auto-apply Compact
gitar auto-apply:on         
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

@romainbrenguier
romainbrenguier enabled auto-merge (squash) August 27, 2026 15:25
@sonarqube-next

Copy link
Copy Markdown
Contributor

@romainbrenguier
romainbrenguier merged commit 6860592 into master Aug 27, 2026
18 checks passed
@romainbrenguier
romainbrenguier deleted the romain/fix-qg branch August 27, 2026 15:42
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

Successfully merging this pull request may close these issues.

2 participants