A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pmd/pmd/issues/3104 below:

[java] False positives for Cloneable rules · Issue #3104 · pmd/pmd · GitHub

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