Affects PMD Version:
6.31.0
Rule(s):
CloneMethodMustImplementCloneable
CloneThrowsCloneNotSupportedException
CloneReturnTypeMustMatchClassName
Description:
False positives for above three rules are reported as follows( ignore line numbers):
DSAlgos/src/main/java/ds/ITreeNode.java:36: CloneMethodMustImplementCloneable: clone() method should be implemented only if implementing Cloneable interface
DSAlgos/src/main/java/ds/ITreeNode.java:36: CloneThrowsCloneNotSupportedException: clone() method should throw CloneNotSupportedException
DSAlgos/src/main/java/ds/TreeNode.java:209: CloneMethodReturnTypeMustMatchClassName: The return type of the clone() method must be the class name when implements Cloneable
DSAlgos/src/main/java/ds/TreeNode.java:209: CloneThrowsCloneNotSupportedException: clone() method should throw CloneNotSupportedException
Code Sample demonstrating the issue:
package ds; interface ITreeNode<E> extends Cloneable { ITreeNode<E> clone(); } package ds; public class TreeNode<T extends Comparable<T>> implements ITreeNode<T> { @Override public ITreeNode<T> clone() { try { return (ITreeNode<T>) super.clone(); } catch (CloneNotSupportedException cnse) { throw new AssertionError("Shouldn't reach here...", cnse); } } }
Expected outcome:
Running PMD through: [CLI | Ant | Maven | Gradle | Designer | Other]
First posted here.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4