Repository navigation
SONARJAVA-7240: Improve S9398 to allow helper and builder types nested in interfaces - #6403
romainbrenguier wants to merge 3 commits into
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>
Code Review ✅ Approved 2 closed / 2 findings🟡 Medium risk · Changing S9398’s helper-type exemptions could suppress findings for nested implementation classes misidentified by signature or Builder name. Refines S9398 so helper types appearing in an interface method's signature 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 2/2 met Repos 4 inspectedFunctional validation No results Rules 2 passed 1 not applicable
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 |
|
⚖️ 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.




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.