Fix for bug [ 2315599 ] False +: UseSingleton with class containing constructor.

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/branches/pmd/4.2.x@6733 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Romain Pelisse 2008-12-02 09:02:44 +00:00
parent f7f2532566
commit d4aad400d5
3 changed files with 26 additions and 2 deletions

View File

@ -5,6 +5,7 @@ Fixed bug 2338341 - ArrayIndexOutOfBoundsException in cpd on rails project
Fixed bug 2315623 - @SuppressWarnings("PMD.UseSingleton") has no effect
Fixed bug 2230809 - False +: ClassWithOnlyPrivateConstructorsShouldBeFinal
Fixed bug 2338341 - ArrayIndexOutOfBoundsException in CPD (on Ruby)
Fixed bug 2315599 - False +: UseSingleton with class containing constructor
October 12, 2008 - 4.2.4:

View File

@ -116,4 +116,24 @@ public class FooTest {
}
]]></code>
</test-code>
<test-code>
<description><![CDATA[
Reproducing bug [ 2315599 ] False +: UseSingleton with class containing constructor: Although there is a static method, the class also has a non-private constructor. This is a common design for custom exceptions which contain a private static method to format error message strings.
]]></description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class UseSingleton extends Exception {
UseSingleton(final String string) {
super(foo(string));
}
private static String foo(final String string) {
return string;
}
}
]]></code>
</test-code>
</test-data>

View File

@ -50,9 +50,12 @@ public class UseSingleton extends AbstractRule {
}
public Object visit(ASTMethodDeclaration decl, Object data) {
methodCount++;
// Private method does no count
if ( ! decl.isPrivate() ) {
methodCount++;
}
if (!isOK && !decl.isStatic()) {
if (!isOK && !decl.isStatic() ) {
isOK = true;
}