SONARJAVA-6716: Fix FN in S8909 for classes with explicit constructors but no no-arg constructor - #5878
SONARJAVA-6716: Fix FN in S8909 for classes with explicit constructors but no no-arg constructor#5878romainbrenguier wants to merge 3 commits into
Conversation
… but no no-arg constructor The hasPublicNoArgsConstructor() method incorrectly returned true for public classes that had explicit constructors but no no-arg constructor. The orElse(classTree.symbol().isPublic()) fallback conflated two cases: classes with no explicit constructors (implicit public no-arg) and classes with explicit constructors that exclude a no-arg option. Split the logic: if no constructors are declared, check class visibility (implicit constructor inherits it); if constructors exist but none is no-arg, return false. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
26d2d72 to
8ffddb9
Compare
… constructor Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add an arg constructor to CacheKeyGeneratorInstantiableCheckSample so it no longer has an implicit public no-arg constructor, making it a non-compliant example for the CacheKeyGeneratorInstantiableCheck rule. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Code Review ✅ Approved 1 resolved / 1 findingsFixes a false negative in rule S8909 for public classes implementing CacheKeyGenerator with explicit constructors by updating no-arg constructor validation. The duplicate verifyAnalysisSucceeds setup logic was also addressed. ✅ 1 resolved✅ Quality: verifyAnalysisSucceeds duplicates verifyAll setup logic
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
CacheKeyGeneratorInstantiableCheck(S8909) where public classes implementingCacheKeyGeneratorwith explicit constructors but no no-arg constructor were not flaggedhasPublicNoArgsConstructor()method now correctly distinguishes between classes with no explicit constructors (implicit default constructor inherits class visibility) and classes with explicit constructors that lack a no-arg optionTest plan
CacheKeyGeneratorInstantiableCheckTest)🤖 Generated with Claude Code
Summary by Gitar
verifyAnalysisSucceeds()method toCheckVerifierto test analysis execution without assertionsThis will update automatically on new commits.