Skip to content

SONARJAVA-6850 Fix SonarQube QG - #6021

Merged
aurelien-coet-sonarsource merged 2 commits into
masterfrom
ac/fix-qg
Aug 25, 2026
Merged

SONARJAVA-6850 Fix SonarQube QG#6021
aurelien-coet-sonarsource merged 2 commits into
masterfrom
ac/fix-qg

Conversation

@aurelien-coet-sonarsource

@aurelien-coet-sonarsource aurelien-coet-sonarsource commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Summary by Gitar

  • Code quality improvements:
    • Added null checks across various check implementations like UnusedLocalVariableCheck and MathOnFloatCheck
    • Replaced subtraction-based comparisons with Integer.compare to prevent overflow issues

This will update automatically on new commits.

@hashicorp-vault-sonar-prod hashicorp-vault-sonar-prod Bot changed the title Fix SonarQube QG SONARJAVA-6850 Fix SonarQube QG Aug 25, 2026
@hashicorp-vault-sonar-prod

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

Copy link
Copy Markdown
Contributor

SONARJAVA-6850

@gitar-bot

gitar-bot Bot commented Aug 25, 2026

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

Adds null checks and integer comparisons across several check implementations to resolve issues with the isRValue null guard and TreeSorter comparisons.

✅ 2 resolved
Bug: isRValue null guard flips result toward false-positive path

📄 java-checks/src/main/java/org/sonar/java/checks/unused/UnusedLocalVariableCheck.java:111-122 📄 java-checks/src/main/java/org/sonar/java/checks/unused/UnusedLocalVariableCheck.java:103-105
In the old code parent.parent() was only evaluated when parent.is(INCREMENT_KINDS) was true (short-circuit &&), so a non-increment parent always yielded true (identifier counted as a read). The rewrite hoists the null check out of the conjunction, so grandParent == null now returns false for any parent kind, and parent == null also returns false; because isUnused uses noneMatch(isRValue), false means "this usage is not a read", i.e. the fallback for an unknown/detached tree now pushes the check toward reporting an unused variable (and offering a quick fix that deletes the declaration) instead of staying silent. Keep the guard inside the increment branch and default the unknown cases to true.

Quality: JavaQuickFix TreeSorter: only last of four comparisons migrated

📄 java-frontend/src/main/java/org/sonar/java/reporting/JavaQuickFix.java:103-109
The PR replaces the subtraction in the final return of TreeSorter.compare with Integer.compare, but the three preceding comparisons in the same method (startLine, startCharacter, endLine) still compute their ordering via subtraction, leaving the mechanical change half applied in a single method. Convert them all so the comparator is consistent (and uniformly overflow-safe).

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

@sonarqube-next

Copy link
Copy Markdown
Contributor

@aurelien-coet-sonarsource
aurelien-coet-sonarsource merged commit 92154da into master Aug 25, 2026
16 checks passed
@aurelien-coet-sonarsource
aurelien-coet-sonarsource deleted the ac/fix-qg branch August 25, 2026 09:56
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