Skip to content

SONARJAVA-7301 Rename local variable to avoid shadowing class field in MethodTreeImpl - #6487

Merged
aurelien-coet-sonarsource merged 1 commit into
masterfrom
remediate-master-20261105-060338-f925e467
Nov 6, 2026
Merged

aurelien-coet-sonarsource merged 1 commit into
masterfrom
remediate-master-20261105-060338-f925e467

Conversation

@sonarqube-agent

Copy link
Copy Markdown
Contributor

This PR was automatically created by the Remediation Agent's Scheduled backlog remediation feature.

Why these issues? This MAJOR severity issue directly addresses the code smell rule java:S1117, which detects problematic variable shadowing. The fix is straightforward and low-risk—a single parameter rename with one corresponding usage update—making it an ideal candidate for automated correction that enhances code clarity without behavioral changes.

Fixed a variable shadowing issue where a local variable named "symbol" in the overriddenSymbols() method was hiding a class field with the same name. The local variable has been renamed to "methodSymbol" to clarify intent and eliminate the shadowing, improving code maintainability and reducing potential confusion.

View Project in SonarCloud


Fixed Issues

java:S1117 - Rename "symbol" which hides the field declared at line 75. • MAJOR • View issue

Location: java:java-frontend/src/main/java/org/sonar/java/model/declaration/MethodTreeImpl.java:300

Why is this an issue?

Shadowing occurs when a local variable has the same name as a variable or a field in an outer scope.

What changed

Renames the local variable "symbol", which hid the class field of the same name, to "methodSymbol" and updates its immediate use in the overriddenSymbols() call. This removes the shadowing.

--- a/java-frontend/src/main/java/org/sonar/java/model/declaration/MethodTreeImpl.java
+++ b/java-frontend/src/main/java/org/sonar/java/model/declaration/MethodTreeImpl.java
@@ -300,2 +300,2 @@ public class MethodTreeImpl extends JavaTree implements MethodTree {
-      Symbol.MethodSymbol symbol = symbol();
-      List<Symbol.MethodSymbol> overriddenSymbols = symbol.overriddenSymbols();
+      Symbol.MethodSymbol methodSymbol = symbol();
+      List<Symbol.MethodSymbol> overriddenSymbols = methodSymbol.overriddenSymbols();

Have a suggestion or found an issue? Share your feedback here.


SonarQube Cloud SonarQube Remediation Agent uses AI. Check for mistakes.

Fixed issues:
- AaGp8UCtNZKwc-1vcC4E for java:S1117 rule

Generated by SonarQube Agent (task: 394197e2-f2b6-42d9-ad1e-1eaa1a4d0e74)
@hashicorp-vault-sonar-prod hashicorp-vault-sonar-prod Bot changed the title Rename local variable to avoid shadowing class field in MethodTreeImpl SONARJAVA-7301 Rename local variable to avoid shadowing class field in MethodTreeImpl Nov 5, 2026
@hashicorp-vault-sonar-prod

hashicorp-vault-sonar-prod Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

SONARJAVA-7301

@gitar-bot

gitar-bot Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Code Review ✅ Approved

🟢 Low risk · Renaming the local variable and its references only clarifies intent; it leaves executable behavior and interfaces unchanged.

Renames the local variable symbol to methodSymbol in overriddenSymbols() within MethodTreeImpl.java, removing the shadowing of the class field with the same name. No issues found.

Verification Rules 1/1 met PRs 1 inspected

Functional validation No results

Rules 1 passed 2 not applicable

✅ Repository license compliance

Broader impact PRs 1 inspected
Cross-PR 1 PR inspected 0 open impacts

PR 6485: SONARJAVA-7300 Decouple the Sonar Java frontend from Eclipse JDT core Inspected

Auto-approval Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

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

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

sonarqube-next Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

@alban-auzeill
alban-auzeill requested review from aurelien-coet-sonarsource and removed request for alban-auzeill November 6, 2026 15:51
@aurelien-coet-sonarsource
aurelien-coet-sonarsource merged commit c03067f into master Nov 6, 2026
22 checks passed
@aurelien-coet-sonarsource
aurelien-coet-sonarsource deleted the remediate-master-20261105-060338-f925e467 branch November 6, 2026 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants