[java] MissingOverride false positive when extending JDK classes
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 42/100
Research direction
Start with pmd-core/src/main/java/net/sourceforge/pmd/lang/document/Chars.java around line 71 and inspect the MissingOverride rule’s reflection and symbol-API handling. Reproduce the report through Maven on Java 17, comparing the JDK classpath behavior across the versions described. Done means the sample no longer produces a false positive while normal override detection remains intact.
Written by the indexing model from the issue text.
Description
Affects PMD Version: 6.53.0
Rule: MissingOverride
Description:
When an application is extending standard JDK classes, then this rule might produce a false positive. Eg. in PMD 7, we extend java.lang.CharSequence and add a method isEmpty without @Override, because this method doesn't exist in Java 8. But it has been added in Java 15.
The rule uses reflection to get the methods of the super class. This depends on the runtime JVM that is used when executing PMD.
In PMD 6, the rule directly uses reflection, so there is no way we could provide a different auxclasspath.
In PMD 7, the rule uses the new symbol API, which uses ASM to load the info from the class files. So we could potentially run PMD with an auxclasspath containing a different JDK classpath than the runtime JVM.
Code Sample demonstrating the issue:
I found this problem when build PMD 7 with Java 17.
Expected outcome:
PMD reports a violation at line 71, but that's wrong. That's a false positive.
Running PMD through: Maven
- Dominant language
- Java
- Stars
- 5.5k
- Forks
- 1.6k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 54
Contributor guide
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.
More from pmd/pmd
-
an:enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
a:bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
an:enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
-
a:bug
-
an:enhancement
Difficulty 3/5 1-2 days Newbie friendliness 68/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
bug needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 1/5 Under an hour Newbie friendliness 94/100
objectionary/hone-maven-plugin#1061 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
spring-projects/spring-modulith#1895 ·