forked from phoedos/pmd
Applied patch from Xavier Le Vourch to reduce false postives from CloneMethodMustImplementCloneable.
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@4505 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -34,6 +34,7 @@ Added new XSLT stylesheet for CPD XML->HTML from Max Tardiveau.
|
||||
Refactored UseIndexOfChar to extract common functionality into AbstractPoorMethodCall.
|
||||
Improved CPD GUI and Designer look/functionality; thanks to Brian Remedios for the changes!
|
||||
Applied patch from Jason Bennett to enhance CyclomaticComplexity rule to account for conditional or/and nodes, do stmts, and catch blocks.
|
||||
Applied patch from Xavier Le Vourch to reduce false postives from CloneMethodMustImplementCloneable.
|
||||
Performance Refactoring, XPath rules re-written as Java:
|
||||
BooleanInstantiation
|
||||
UselessOperationOnImmutable
|
||||
|
@ -19,6 +19,7 @@ public class CloneMethodMustImplementCloneableTest extends SimpleAggregatorTst {
|
||||
new TestDescriptor(TEST1, "ok, implements Cloneable", 0, rule),
|
||||
new TestDescriptor(TEST2, "bad, doesn't implement Cloneable", 1, rule),
|
||||
new TestDescriptor(TEST3, "ok, not Object.clone since method has a param", 0, rule),
|
||||
new TestDescriptor(TEST4, "ok, doesn't implement Cloneable but only throw CloneNotSupportedException", 0, rule),
|
||||
});
|
||||
}
|
||||
|
||||
@ -36,4 +37,8 @@ public class CloneMethodMustImplementCloneableTest extends SimpleAggregatorTst {
|
||||
"public class Foo {" + PMD.EOL +
|
||||
" void clone(int x) {}" + PMD.EOL +
|
||||
"}";
|
||||
private static final String TEST4 =
|
||||
"public class Foo {" + PMD.EOL +
|
||||
" final Object clone() { throw new CloneNotSupportedException(); }" + PMD.EOL +
|
||||
"}";
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ and count(NameList/Name[contains
|
||||
class="net.sourceforge.pmd.rules.XPathRule"
|
||||
externalInfoUrl="http://pmd.sourceforge.net/rules/clone.html#CloneMethodMustImplementCloneable">
|
||||
<description>
|
||||
The method clone() should only be implemented if the class implements the Cloneable interface
|
||||
The method clone() should only be implemented if the class implements the Cloneable interface with the exception of a final method that only throws CloneNotSupportedException
|
||||
</description>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
@ -98,8 +98,15 @@ The method clone() should only be implemented if the class implements the Clonea
|
||||
//ClassOrInterfaceDeclaration
|
||||
[not(./ImplementsList/ClassOrInterfaceType
|
||||
[@Image='Cloneable'])]
|
||||
[.//MethodDeclaration/MethodDeclarator[@Image
|
||||
[.//MethodDeclaration
|
||||
[MethodDeclarator[@Image
|
||||
= 'clone' and count(FormalParameters/*) = 0]]
|
||||
[not((../MethodDeclaration[@Final = 'true'])
|
||||
and Block[count(BlockStatement)=1]
|
||||
/BlockStatement/Statement/ThrowStatement/Expression
|
||||
/PrimaryExpression/PrimaryPrefix/AllocationExpression
|
||||
/ClassOrInterfaceType[@Image = 'CloneNotSupportedException'])]]
|
||||
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
|
@ -48,6 +48,7 @@
|
||||
</subsection>
|
||||
<subsection name="Contributors">
|
||||
<ul>
|
||||
<li>Xavier Le Vourch - Patch to improve CloneMethodMustImplementCloneable, suggestions on cleaning up casts in grammar, SimplifyBooleanAssertion, patch to fix problem with TestClassWithoutTestCases, patch to fix rule name bugs in migration rulesets</li>
|
||||
<li>Jason Bennett - Patch to improve CyclomaticComplexity rule</li>
|
||||
<li>Wouter Zelle - Wrote BrokenNullCheck rule, fixed a false positive in InefficientStringBuffering, fixed a false positive in NonThreadSafeSingleton, a nice patch to clean up some of the Ant task properties and fix a TextRenderer bug, rewrote PositionLiteralsFirstInComparisons in XPath, Renderer improvement suggestions, wrote NonThreadSafeSingleton rule, wrote DefaultPackage rule, worked thru ASTMethodDeclaration.isSyntacticallyX design, reported docs bug 1292689 for UnnecessaryLocalBeforeReturn, reported leftover ExceptionTypeChecking source file, rewrote UselessOverridingMethod in Java, UselessOverridingMethod rule, ProperLogger rule, nifty code to allow variables in XPath rules, externalInfoUrl data for all rules in basic and unusedcode rulesets, some very nifty XSLT, improvements to UseCorrectExceptionLogging, designed and implemented the "externalInfoUrl" feature in the rule definitions, fixed a devious bug in RuleSetFactory, AvoidPrintStackTrace, initial implementation of SimplifyConditional</li>
|
||||
<li>Sven Jacob - Some fixes for the DFA layer.</li>
|
||||
@ -77,7 +78,6 @@
|
||||
<li>David Karr - reported stale XPath documentation</li>
|
||||
<li>Dawid Weiss - Reported bug in UnusedPrivateMethod</li>
|
||||
<li>Shao Lo - Reported bug in CPD</li>
|
||||
<li>Xavier Le Vourch - Suggestions on cleaning up casts in grammar, SimplifyBooleanAssertion, patch to fix problem with TestClassWithoutTestCases, patch to fix rule name bugs in migration rulesets</li>
|
||||
<li>Mathieu Champlon - Added language support to the CPD Ant task</li>
|
||||
<li>Uroshnor - Reported bug in UseNotifyAllInsteadOfNotify</li>
|
||||
<li>Jan Koops - Noted missing data in MemberValuePair nodes, bug report for JBuilder plugin</li>
|
||||
|
Reference in New Issue
Block a user