-
Notifications
You must be signed in to change notification settings - Fork 724
SONARJAVA-6757: Fix FP in S9149 for intentional hiding with deprecation annotations #5924
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,7 +41,7 @@ public void visitNode(Tree tree) { | |
| } | ||
| MethodTree methodTree = (MethodTree) tree; | ||
| Symbol.MethodSymbol methodSymbol = methodTree.symbol(); | ||
| if (!methodSymbol.isStatic()) { | ||
| if (!methodSymbol.isStatic() || isIntentionalHiding(methodSymbol)) { | ||
| return; | ||
| } | ||
| Symbol.TypeSymbol owner = (Symbol.TypeSymbol) methodSymbol.owner(); | ||
|
|
@@ -79,6 +79,11 @@ private void reportHidingIssue(MethodTree methodTree, Symbol.MethodSymbol method | |
| } | ||
| } | ||
|
|
||
| private static boolean isIntentionalHiding(Symbol.MethodSymbol methodSymbol) { | ||
| return methodSymbol.metadata().isAnnotatedWith("java.lang.Deprecated") | ||
| || methodSymbol.metadata().isAnnotatedWith("com.google.errorprone.annotations.DoNotCall"); | ||
| } | ||
|
Comment on lines
+82
to
+85
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Edge Case: @deprecated blanket-suppresses S9149, risking false negativesisIntentionalHiding treats any @deprecated hiding method as intentional. @deprecated is applied for many reasons unrelated to method hiding (e.g. a method scheduled for removal that accidentally hides a parent static method), so this may suppress genuinely accidental hiding that developers still want flagged. This is a reasonable tradeoff to remove the Guava FPs, but consider whether @DonotCall alone (a much more specific signal) would suffice, or document this broadening in the rule metadata so users understand deprecated methods are now exempt. Was this helpful? React with 👍 / 👎 |
||
|
|
||
| private static boolean hasSameParameterTypes(Symbol.MethodSymbol method, Symbol.MethodSymbol candidate) { | ||
| List<Type> methodParams = method.parameterTypes(); | ||
| List<Type> candidateParams = candidate.parameterTypes(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could be worth considering additional common decorators with similar meaning:
com.google.errorprone.annotations.InlineMeorg.jetbrains.annotations.ApiStatus.Obsoleteorg.jetbrains.annotations.ApiStatus.ScheduledForRemovalkotlin.DeprecatedAlso, have you considered updating the RSPEC to document these exceptions?