[java] MissingOverride false positive when extending JDK classes

Open
#4,291 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
42/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
java
Domain
devtools

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

a:false-positive

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:

https://github.com/pmd/pmd/blob/9964f116a4f970713de40437ce7e585780192486/pmd-core/src/main/java/net/sourceforge/pmd/lang/document/Chars.java#L71

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from pmd/pmd

All issues in pmd/pmd

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.