Skip to content

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

Open
rombirli wants to merge 4 commits into
masterfrom
rombirli/implement-qualified-this
Open

rombirli wants to merge 4 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
@gitar-bot

gitar-bot Bot commented Oct 15, 2026

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

🟡 Medium risk · Adding S9434 detects redundant qualified-this expressions; incorrect enclosing-class detection could flag necessary qualifiers or miss readability issues.

Implements rule S9434 to flag qualified this expressions 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 moved onto the filter line and the spec was fixed, addressing the review finding.

✅ 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 1/1 met Repos 3 inspected · PRs 2 inspected

Functional validation No results

Rules 1 passed 2 not applicable

✅ Repository license compliance

Broader impact Repos 3 inspected PRs 2 inspected
Cross-repo 3 repositories inspected 0 open impacts

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

Cross-PR 2 PRs inspected 0 open impacts

PR #6308: SONARJAVA-7137 Optionally rely on source paths to resolve types during analyses Inspected
PR #6309: SONARJAVA-7138 [DO-NOT-MERGE] Add optional compilation phase before analysis 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

This branch has not been deployed

No deployments
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.

1 participant