Skip to content

SONARJAVA-7161 Implement rule S9434 - Qualified "this" should not be used when the unqualified form is enough - #6360

Merged
rombirli merged 6 commits into
masterfrom
rombirli/implement-qualified-this
Oct 21, 2026
Merged

rombirli merged 6 commits into
masterfrom
rombirli/implement-qualified-this

Conversation

@rombirli

Copy link
Copy Markdown
Contributor

Implements rule S9434.

A qualified this whose qualifier names the innermost enclosing class resolves to the same object as a plain this, so the qualifier carries no information and misleads the reader into looking for an enclosing instance that is not involved. Lambda bodies are treated as transparent because a lambda does not introduce its own this, while anonymous, inner and local classes do and keep their qualifier.

@hashicorp-vault-sonar-prod

hashicorp-vault-sonar-prod Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

SONARJAVA-7161

Comment thread sonar-java-plugin/src/main/resources/org/sonar/l10n/java/rules/java/S9434.html Outdated
@datadog-sonarsource

This comment has been minimized.

@github-actions

Copy link
Copy Markdown
Contributor

⚖️ Ruling update ready for review: #6361

@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Ruling Diff Summary

Detected changes in 3 rule files: 0 issues removed, 12 issues added.

S9434 (java) on eclipse-jetty - 0 issues removed, 8 issues added - new ruling file

Added jetty-io/src/main/java/org/eclipse/jetty/io/ssl/SslConnection.java (line 371)

(source file not found at this revision: jetty-io/src/main/java/org/eclipse/jetty/io/ssl/SslConnection.java)

Added jetty-io/src/main/java/org/eclipse/jetty/io/ssl/SslConnection.java (line 380)

(source file not found at this revision: jetty-io/src/main/java/org/eclipse/jetty/io/ssl/SslConnection.java)

Added jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannel.java (line 370)

(source file not found at this revision: jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannel.java)

Added jetty-util/src/main/java/org/eclipse/jetty/util/RolloverFileOutputStream.java (line 410)

(source file not found at this revision: jetty-util/src/main/java/org/eclipse/jetty/util/RolloverFileOutputStream.java)

Added jetty-util/src/main/java/org/eclipse/jetty/util/RolloverFileOutputStream.java (line 411)

(source file not found at this revision: jetty-util/src/main/java/org/eclipse/jetty/util/RolloverFileOutputStream.java)

Added jetty-util/src/main/java/org/eclipse/jetty/util/RolloverFileOutputStream.java (line 412)

(source file not found at this revision: jetty-util/src/main/java/org/eclipse/jetty/util/RolloverFileOutputStream.java)

Added jetty-util/src/main/java/org/eclipse/jetty/util/ssl/SslSelectionDump.java (line 46)

(source file not found at this revision: jetty-util/src/main/java/org/eclipse/jetty/util/ssl/SslSelectionDump.java)

Added jetty-util/src/main/java/org/eclipse/jetty/util/thread/ScheduledExecutorScheduler.java (line 99)

(source file not found at this revision: jetty-util/src/main/java/org/eclipse/jetty/util/thread/ScheduledExecutorScheduler.java)
S9434 (java) on eclipse-jetty-similar-to-main - 0 issues removed, 3 issues added - new ruling file

Added jetty-io/src/main/java/org/eclipse/jetty/io/ssl/SslConnection.java (line 371)

(source file not found at this revision: jetty-io/src/main/java/org/eclipse/jetty/io/ssl/SslConnection.java)

Added jetty-io/src/main/java/org/eclipse/jetty/io/ssl/SslConnection.java (line 380)

(source file not found at this revision: jetty-io/src/main/java/org/eclipse/jetty/io/ssl/SslConnection.java)

Added jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannel.java (line 370)

(source file not found at this revision: jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannel.java)
S9434 (java) on guava - 0 issues removed, 1 issues added - new ruling file

Added src/com/google/common/collect/TreeRangeMap.java (line 547)

       542 |         return !toRemove.isEmpty();
       543 |       }
       544 | 
       545 |       @Override
       546 |       public Set<Range<K>> keySet() {
>>>    547 |         return new Maps.KeySet<Range<K>, V>(SubRangeMapAsMap.this) {
       548 |           @Override
       549 |           public boolean remove(@Nullable Object o) {
       550 |             return SubRangeMapAsMap.this.remove(o) != null;
       551 |           }
       552 |           

@github-actions

Copy link
Copy Markdown
Contributor

⚖️ Ruling update ready for review: #6361

@rombirli
rombirli force-pushed the rombirli/implement-qualified-this branch from 66e2c9c to 8bc4ce3 Compare October 15, 2026 12:24
@rombirli
rombirli force-pushed the rombirli/implement-qualified-this branch from 8bc4ce3 to cdc501f Compare October 15, 2026 12:47
@rombirli

Copy link
Copy Markdown
Contributor Author

/pvf

@hashicorp-vault-sonar-prod

Copy link
Copy Markdown
Contributor

📊 Performance Validation complete
🆕 328 new · 🗑️ 0 lost issues
View dashboard

@rombirli
rombirli requested a review from nathsou October 19, 2026 12:26
@rombirli

Copy link
Copy Markdown
Contributor Author

/pvf

@hashicorp-vault-sonar-prod

Copy link
Copy Markdown
Contributor

📊 Performance Validation complete
🆕 623 new · 🗑️ 262 lost issues
View dashboard

Comment thread sonar-java-plugin/src/main/resources/org/sonar/l10n/java/rules/java/S9434.html Outdated
@gitar-bot

gitar-bot Bot commented Oct 20, 2026 •

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

🟡 Medium risk · Adding S9434 detection and a quick fix changes reported findings and could remove a needed qualifier if enclosing-class resolution is mistaken.

Implements rule S9434 to flag qualified this references whose qualifier names the innermost enclosing class, since they resolve to the same object as a plain this. Lambda bodies are treated as transparent, while anonymous, inner and local classes keep their qualifier. The lambda explanation in the HTML example was clarified, addressing the related finding. No open issues remain.

✅ 1 closed
✅ Quality: Lambda explanation sits on the line with no lambda in the HTML example

📄 sonar-java-plugin/src/main/resources/org/sonar/l10n/java/rules/java/S9434.html:50-51
In the noncompliant example in S9434.html, the comment // Noncompliant: a lambda does not introduce its own "this" is on line 50, return Invoice.this.lines.stream(). That line is a plain method-body access, not code inside a lambda. The occurrence that actually sits in a lambda, line.startsWith(Invoice.this.id) on line 51, has no marker. A reader learning about the lambda case will look at the wrong expression, and the example shows two issues while only one is marked. Mark line 50 as a plain redundant qualifier and move the lambda explanation to line 51.

Verification Rules 2/2 met Repos 8 inspected · PRs 1 inspected

Functional validation No results

Rules 2 passed 1 not applicable

✅ Internal artifact registries
✅ Repository license compliance

Broader impact Repos 8 inspected PRs 1 inspected
Cross-repo 8 repositories inspected 0 open impacts

SonarSource/sonarlint-vscode Inspected
SonarSource/sonarlint-intellij Inspected
SonarSource/sonarlint-core Inspected
SonarSource/sonarlint-language-server Inspected
SonarSource/sonar-java-symbolic-execution Inspected

3 more repositories

Cross-PR 1 PR inspected 0 open impacts

PR 6353: SONARJAVA-7162 Implement rule S9435 - Ternary operator conditions should not be negated 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

Copy link
Copy Markdown
Contributor

@rombirli

Copy link
Copy Markdown
Contributor Author

/pvf

@hashicorp-vault-sonar-prod

Copy link
Copy Markdown
Contributor

📊 Performance Validation complete
🆕 328 new · 🗑️ 0 lost issues
View dashboard

@rombirli
rombirli merged commit 36647d6 into master Oct 21, 2026
21 checks passed
@rombirli
rombirli deleted the rombirli/implement-qualified-this branch October 21, 2026 09:21
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