Skip to content

SONARJAVA-6654 Fix S2166 false positives for classes with unresolvable supertypes#5832

Merged
asya-vorobeva merged 1 commit into
masterfrom
asya/fix-fp-s2166
Jul 23, 2026
Merged

SONARJAVA-6654 Fix S2166 false positives for classes with unresolvable supertypes#5832
asya-vorobeva merged 1 commit into
masterfrom
asya/fix-fp-s2166

Conversation

@asya-vorobeva

Copy link
Copy Markdown
Contributor

Guard against ECJ batch mode behavior where a compilation error causes superClass() to return null instead of UnknownType, which was triggering false positives on classes with an extends clause.

@hashicorp-vault-sonar-prod

hashicorp-vault-sonar-prod Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

SONARJAVA-6654

@erwan-leforestier-sonarsource

Copy link
Copy Markdown

I don't see any unit test to make sure it's fine. Is it possible to add one ?

@asya-vorobeva

Copy link
Copy Markdown
Contributor Author

I don't see any unit test to make sure it's fine. Is it possible to add one ?

Unfortunately no. This situation happens in very specific case when the project fails to be parsed with ECJ parser (which we use in default batch mode). The problem is that our unit tests always use JParser, so this path is inherently untestable at the unit level. And our ruling projects also don't satisfy this condition. I've already added defensive comment to clarify this.

Guard against ECJ batch mode behavior where a compilation error causes
superClass() to return null instead of UnknownType, which was triggering
false positives on classes with an extends clause.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@sonarqube-next

Copy link
Copy Markdown

@asya-vorobeva
asya-vorobeva merged commit dc4ea3e into master Jul 23, 2026
17 checks passed
@asya-vorobeva
asya-vorobeva deleted the asya/fix-fp-s2166 branch July 23, 2026 07:57
@gitar-bot

gitar-bot Bot commented Jul 23, 2026

Copy link
Copy Markdown
Code Review 👍 Approved with suggestions 0 resolved / 1 findings

Prevents S2166 false positives in ECJ batch mode by handling null return values from superClass() during resolution. Please add regression test coverage to verify the fix.

💡 Quality: No test coverage added for the FP fix

Reply with Gitar … to ask about this finding.

The PR fixes an S2166 false positive but the diff contains no changes to test files or test sources. Without a regression test that reproduces the ECJ-batch case (an extends clause in the AST while symbol.superClass() returns null), the fix could silently regress. Add a test case exercising a class named like an exception with an unresolvable supertype to lock in the new behavior.

🤖 Prompt for agents
Code Review: Prevents S2166 false positives in ECJ batch mode by handling null return values from superClass() during resolution. Please add regression test coverage to verify the fix.

1. 💡 Quality: No test coverage added for the FP fix

   The PR fixes an S2166 false positive but the diff contains no changes to test files or test sources. Without a regression test that reproduces the ECJ-batch case (an `extends` clause in the AST while `symbol.superClass()` returns null), the fix could silently regress. Add a test case exercising a class named like an exception with an unresolvable supertype to lock in the new behavior.

Options

Auto-apply is off → Gitar will not commit updates to this branch.
Display: compact → Showing less information.

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

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