[java] False positive for UseInstanceofToCompareClasses on local generic class
Open
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 5
- Forks
- 13
- Avg merge
- 17h 48m
- Merged PRs (30d)
- 9
Description
UseInstanceofToCompareClasses reports on non-reifiable types, even though they're not acceptable as operand to instanceof. E.g.:
class Foo<T> {
public Foo<T> wrap() {
// since the local class is not static, the T here refers to the T of the outer instance
class MyWrapper extends Foo<T> {
}
this instanceof MyWrapper // -> error, MyWrapper is not reifiable, because its supertype Foo<T> isn't
this.getClass().equals(MyWrapper.class) // this is the only way to compare it
}
}
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the UseInstanceofToCompareClasses rule and reproduce the provided local generic-class example. Check how the rule determines whether the instanceof operand is valid, then verify that this non-reifiable MyWrapper case is ignored while valid comparisons still produce findings.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100