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:
- No violations must be reported.
Running PMD through: [CLI | Ant | Maven | Gradle | Designer | Other]
First posted here.
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):
Code Sample demonstrating the issue:
Expected outcome:
Running PMD through: [CLI | Ant | Maven | Gradle | Designer | Other]
First posted here.