-
Notifications
You must be signed in to change notification settings - Fork 716
SONARJAVA-5936 : S1452 Remove FPs for wildcards in nested types #5391
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?
SONARJAVA-5936 : S1452 Remove FPs for wildcards in nested types #5391
Conversation
BartLucien
left a comment
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.
I just have a small comment concerning the tests.
While it may create some false negatives, as having wildcard in nested types won't be detected. I think it is better than having a issue raised that breaks the compilation if it is fixed. What do you think?
I do not approve as I think there should be a more authoritative answer to your concern.
| private static class B extends checks.A { | ||
| } | ||
| } | ||
|
|
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.
I would add another example with another data structure to have a more robust test. Something similar to the FP that disappeared from the ITS tests seem like good candidates to me.
08adf1a to
c96bddd
Compare
|
| private static class A { | ||
| } | ||
|
|
||
| private static class B extends checks.A { |
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.
Is there a particulat reason to use checks.A rather than just A?
| import java.util.List; | ||
| import java.util.ArrayList; | ||
|
|
||
| public class WildCardReturnParameterNestedTypeCheck { |
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's easier to find samples if the filename ends in ...Sample.java. Maybe we can rename all sample for this check?





This PR aims to remove False Positives (FPs) in code examples involving nested generics, such as:
The Proposed Solution:
The fix stops checking wildcards after depth 1 nested types (i.e., removing the recursive check).
Reviewer Note:
Please pay attention to this change in behavior; while it resolves the FPs, it means the rule will no longer flag potential issues in deeper nested structures. I would like your feedback on whether this trade-off makes sense or if we should consider a more surgical approach to the recursion.