diff --git a/pmd/etc/bug_closer.txt b/pmd/etc/bug_closer.txt index 51bfd3aa4c..0dcde848b8 100644 --- a/pmd/etc/bug_closer.txt +++ b/pmd/etc/bug_closer.txt @@ -7,5 +7,5 @@ that contains this fix. Thanks, Tom -Using PMD? Get the book, "PMD Applied"! http://pmdapplied.com/ +Support PMD, get the book: http://pmdapplied.com/ diff --git a/pmd/etc/changelog.txt b/pmd/etc/changelog.txt index 7b8d6fe773..805b5b5736 100644 --- a/pmd/etc/changelog.txt +++ b/pmd/etc/changelog.txt @@ -16,6 +16,7 @@ Fixed bug 1378358 - StringInstantiation no longer throws ClassCastExceptions on Fixed bug 1371741 - UncommentedEmptyConstructor no longer flags constructors that consist of a this() or a super() invocation. Fixed bug 1277373 - InefficientStringBuffering no longer flags concatenations that involve a static final String. Fixed bug 1379701 - CompareObjectsWithEquals no longer flags comparisons of array elements. +Fixed bug 1380969 - UnusedPrivateMethod no longer flags private static methods that are only invoked in a static context from a field declaration. Fixed a bug in UseStringBufferLength; it no longers fails with an exception on expressions like StringBuffer.toString.equals(x) Partially fixed bug 1371753 - UnnecessaryLocalBeforeReturn message now reflects the fact that that rule flags all types Modified renderers to support disabling printing of suppressed warnings. Introduced a new AbstractRenderer class that all Renderers can extends to get the current behavior - that is, suppressed violations are printed. diff --git a/pmd/regress/test/net/sourceforge/pmd/rules/UnusedPrivateMethodRuleTest.java b/pmd/regress/test/net/sourceforge/pmd/rules/UnusedPrivateMethodRuleTest.java index 6168347d37..6b2f34fe26 100644 --- a/pmd/regress/test/net/sourceforge/pmd/rules/UnusedPrivateMethodRuleTest.java +++ b/pmd/regress/test/net/sourceforge/pmd/rules/UnusedPrivateMethodRuleTest.java @@ -33,7 +33,8 @@ public class UnusedPrivateMethodRuleTest extends SimpleAggregatorTst { new TestDescriptor(TEST11, "called from constructor", 0, rule), new TestDescriptor(TEST12, "private method with same name but diff arg count than public method", 0, rule), new TestDescriptor(TEST13, "static private called from initializer", 0, rule), - // FIXME new TestDescriptor(TEST14, "two methods, one private, one public, same name, same arg count, diff types", 0, rule), + new TestDescriptor(TEST14, "static private invoked in static context - i.e., Foo.hi()", 0, rule), + // FIXME new TestDescriptor(TEST15, "two methods, one private, one public, same name, same arg count, diff types", 0, rule), }); } @@ -153,6 +154,12 @@ public class UnusedPrivateMethodRuleTest extends SimpleAggregatorTst { private static final String TEST14 = "public class Foo {" + PMD.EOL + + " static boolean BUZ = Foo.bar(); " + PMD.EOL + + " private static boolean bar() { return true; }" + PMD.EOL + + "}"; + + private static final String TEST15 = + "public class Foo {" + PMD.EOL + " public void baz() {" + PMD.EOL + " foo(\"hi\");" + PMD.EOL + " }" + PMD.EOL + diff --git a/pmd/src/net/sourceforge/pmd/rules/UnusedPrivateMethodRule.java b/pmd/src/net/sourceforge/pmd/rules/UnusedPrivateMethodRule.java index d3a2604753..29bde1ce9c 100644 --- a/pmd/src/net/sourceforge/pmd/rules/UnusedPrivateMethodRule.java +++ b/pmd/src/net/sourceforge/pmd/rules/UnusedPrivateMethodRule.java @@ -62,7 +62,7 @@ public class UnusedPrivateMethodRule extends AbstractRule { } ASTMethodDeclaration enclosingMethod = (ASTMethodDeclaration)occNode.getFirstParentOfType(ASTMethodDeclaration.class); - if (enclosingMethod != null && !mnd.getNode().jjtGetParent().equals(enclosingMethod)) { + if ((enclosingMethod == null) || (enclosingMethod != null && !mnd.getNode().jjtGetParent().equals(enclosingMethod))) { callsFromOutsideMethod++; } }