forked from phoedos/pmd
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:
parent
f7f2532566
commit
d4aad400d5
@ -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:
|
||||
|
||||
|
@ -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>
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user