You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[java] CloneMethodMustImplementCloneable: False positive when Cloneable is a super interface #6345
if a class implements the clone method and implements an interface, and that interface has as a super interface Cloneable, then PMD reports it has failing this rule, when in fact it does inherit from Cloneable
I have verified this code sample against PMD 7.20.0 and can confirm that the issue is no longer reproducible. The rule now correctly identifies the usage, and no false positive is reported.
I recommend upgrading to the latest version to resolve this.
I have verified this code sample against PMD 7.20.0 and can confirm that the issue is no longer reproducible. The rule now correctly identifies the usage, and no false positive is reported.
Hi @pzygielo, sorry for the inconvenience. I downloaded the official release 7.20.0, and this appears to be a confirmed false positive.
pmd check \
-d MyExample.java \
-R category/java/errorprone.xml,category/java/bestpractices.xml \
-f text
---
[WARN] Progressbar rendering conflicts with reporting to STDOUT. No progressbar will be shown. Try running with argument -r <file> to output the report to a file instead.
[WARN] This analysis could be faster, please consider using Incremental Analysis: https://docs.pmd-code.org/latest/pmd_userdocs_incremental_analysis.html
MyExample.java:5: MissingOverride: The method 'clone()' is missing an @Override annotation.
MyExample.java:9: PreserveStackTrace: Thrown exception does not preserve the stack trace of exception 'e' on all code paths
It turns out that I didn’t reproduce the issue correctly locally. I’ll get back to you as soon as I do
MyExample.java:3: CloneMethodMustImplementCloneable: clone() method should be implemented only if implementing Cloneable interface
This is a false positive. The rule fails to recognize that MyExample implements Cloneable transitively through MyC when they're defined in separate files.
My initial test had both declarations in a single file, which is why I couldn't reproduce it originally. The issue is confirmed in PMD 7.20.0.
@pzygielo - Is checking interface hierarchies across separate files the expected behavior for this rule, or should it require auxclasspath configuration?
@mdhamed238 are you sure you are providing a complete auxclasspath? the fact it works when using a single source files makes me believe you are not…
Without a complete auxclasspath, PMD simply can't know what is in MyC, or wether it implements Cloneable or not.
The original report by @mebigfatguy mentions he is using Ant, which does support the param, but requires manual setting of it + ensuring the code is built before running PMD (unlike Maven and Gradle that manages everything automatically).
@jsotuyod Thanks for the clarification. So --aux-classpath is needed to tell PMD where the compiled classes are, allowing it to resolve the interface hierarchy (MyC → Cloneable) across separate files.
Reacted by Juan Martín Sotuyo Dodero and Clément Fournier
changed the title [-][java] CloneMethodMustImplementCloneable doesn't look for Cloneable as a Super interface[/-][+][java] CloneMethodMustImplementCloneable: False positive when Cloneable is a super interface[/+]on Jan 16, 2026
Activity
mdhamed238 commentedon Dec 28, 2025
I'm on it.
mdhamed238 commentedon Dec 29, 2025
Hi @mebigfatguy,
I have verified this code sample against PMD 7.20.0 and can confirm that the issue is no longer reproducible. The rule now correctly identifies the usage, and no false positive is reported.
I recommend upgrading to the latest version to resolve this.
pzygielo commentedon Dec 29, 2025
Just to confirm - at this very moment 7.19.0 IS the latest version, right?
pzygielo commentedon Dec 29, 2025
Is it possible to clarify which code change in https://github.com/pmd/pmd/releases/tag/pmd_releases%2F7.20.0-SNAPSHOT changed/fixed that?
mdhamed238 commentedon Dec 29, 2025
Hi @pzygielo, sorry for the inconvenience. I downloaded the official release 7.20.0, and this appears to be a confirmed false positive.
It turns out that I didn’t reproduce the issue correctly locally. I’ll get back to you as soon as I do
mdhamed238 commentedon Dec 29, 2025
Update: The bug occurs when the interface and class are in separate files.
MyC.java:
MyExample.java:
Output:
This is a false positive. The rule fails to recognize that
MyExampleimplementsCloneabletransitively throughMyCwhen they're defined in separate files.My initial test had both declarations in a single file, which is why I couldn't reproduce it originally. The issue is confirmed in PMD 7.20.0.
@pzygielo - Is checking interface hierarchies across separate files the expected behavior for this rule, or should it require auxclasspath configuration?
jsotuyod commentedon Dec 29, 2025
@mdhamed238 are you sure you are providing a complete
auxclasspath? the fact it works when using a single source files makes me believe you are not…Without a complete auxclasspath, PMD simply can't know what is in
MyC, or wether it implementsCloneableor not.The original report by @mebigfatguy mentions he is using
Ant, which does support the param, but requires manual setting of it + ensuring the code is built before running PMD (unlike Maven and Gradle that manages everything automatically).mdhamed238 commentedon Dec 29, 2025
@jsotuyod Thanks for the clarification. So --aux-classpath is needed to tell PMD where the compiled classes are, allowing it to resolve the interface hierarchy (MyC → Cloneable) across separate files.
[-][java] CloneMethodMustImplementCloneable doesn't look for Cloneable as a Super interface[/-][+][java] CloneMethodMustImplementCloneable: False positive when Cloneable is a super interface[/+]UncleOwen commentedon Apr 22, 2026
This exact feature has been implemented in #1532 on sourceforge and has tests that verify it works.
I just tried the exact code from the first post in current main and didn't get a warning. Closing as can't reproduce.