Repository navigation
SONARJAVA-7240: Improve S9398 to allow helper and builder types nested in interfaces - #6403
Conversation
…n interfaces Nested classes are no longer reported when they are builders or appear in the signature (return type, parameter types, thrown exceptions) of a method of the enclosing interface, unless they implement that interface. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
|
⚖️ Ruling update ready for review: #6404 |
Ruling Diff SummaryDetected changes in 3 rule files: 10 issues removed, 0 issues added. S9398 (
|
…erface once Helper types are now matched by symbol instead of simple name, so unrelated qualified types and method type parameters no longer hide issues. The check visits interfaces and collects signature types once per interface. The name-based fallback for unknown types is removed, and ruling expectations are updated. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…ilar-to-main Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
|
⚖️ Ruling update ready for review: #6405 |
| * or when it appears in the signature (return type, parameter types or thrown exceptions) | ||
| * of a method declared by the interface. | ||
| */ | ||
| private static boolean isHelperType(ClassTree classTree, Set<Symbol> signatureTypes) { |
There was a problem hiding this comment.
[nit] Generic helper types are still reported
interface GenericDto {
Helper<String> helper();
class Helper<T> {}
}Helper is incorrectly reported despite being an interface return type. The collected Helper<String> symbol differs from the Helper<T> declaration, so signatureTypes.contains(classTree.symbol()) returns false. Normalize both symbols to their declarations or erased types before comparing, and add regression coverage for generic return and parameter types.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Code Review ✅ Approved 2 closed / 2 findings🟡 Medium risk · S9398 now exempts nested types used in method signatures and non-implementing classes ending in Builder, which could let implementation code evade the diagnostic. Relaxes S9398 so helper types appearing in an enclosing interface's method signatures and classes named ✅ 2 closed✅ Edge Case: Helper detection matches simple names, so unrelated types hide issues
✅ Performance: Interface method signatures are re-scanned for every nested class
Verification Rules 1/2 met Repos 4 inspectedRules 1 failed 1 passed 1 not applicable
Functional validation No results Broader impact Repos 4 inspectedCross-repo 4 repositories inspected 0 open impacts
Auto-approval Not enabledFor more verification details, comment OptionsAuto-apply is off → Gitar will not commit updates to this branch. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Gitar |
|




Summary
S9398 (Inner classes should not be declared inside interfaces) now uses a better heuristic to tell legitimate nested types from implementation code:
isSubtypeOf; without semantic it compares the names of the direct supertypes.Builder.Notes
🤖 Generated with Claude Code
Agent workflow
Tool link: https://github.com/SonarSource/languages-experimental-tooling/tree/romain/my-tickets/personal/romain-brenguier
PR created using
uv run create_with_claude.py SONARJAVA-7240.txtPR updated using
uv run update_with_claude.py --prompt "Implement the action plan described in the document /tmp/action_plan_romain/sonarjava-7240.txt." -a "/tmp/action_plan_romain/sonarjava-7240.txt" -g "claude"PR updated using
uv run update_with_claude.py --prompt "Implement the action plan described in the document /tmp/action_plan_romain/sonarjava-7240.txt." -a "/tmp/action_plan_romain/sonarjava-7240.txt" -g "claude"Iterated on the PR with
uv run ci_loop.pyfor 2 iterations.✔️ The PR is now ready for review.
Addressed review comments in pr_report_6403.md using
uv run address_reviews.py pr_report_6403.md