Fixed bug 2230809 - False +: ClassWithOnlyPrivateConstructorsShouldBeFinal

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/branches/pmd/4.2.x@6703 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Xavier Le Vourch 2008-11-27 17:06:30 +00:00
parent 8f8afde50b
commit 0252a9c905
3 changed files with 62 additions and 1 deletions

View File

@ -3,6 +3,7 @@
Enhanced logging in the ClassTypeResolver to provide more detailed messaging.
Fixed bug 2338341 - ArrayIndexOutOfBoundsException in cpd on rails project
Fixed bug 2315623 - @SuppressWarnings("PMD.UseSingleton") has no effect
Fixed bug 2230809 - False +: ClassWithOnlyPrivateConstructorsShouldBeFinal
October 12, 2008 - 4.2.4:

View File

@ -80,6 +80,64 @@ public class Foo {
}
public class Bar extends Foo {
public Bar() { }
}
]]></code>
</test-code>
<test-code>
<description><![CDATA[
One protected constructor, not required to be final
]]></description>
<expected-problems>0</expected-problems>
<code><![CDATA[
class ClassWithOnlyPrivateConstructorsShouldBeFinal {
private String string;
protected ClassWithOnlyPrivateConstructorsShouldBeFinal(final Object object) {
this(object.toString());
}
private ClassWithOnlyPrivateConstructorsShouldBeFinal(final String string) {
super();
setString(string);
}
public final void setString(final String string) {
this.string = string;
}
public String getString() {
return string;
}
}
]]></code>
</test-code>
<test-code>
<description><![CDATA[
One package private constructor, not required to be final
]]></description>
<expected-problems>0</expected-problems>
<code><![CDATA[
class ClassWithOnlyPrivateConstructorsShouldBeFinal {
private String string;
ClassWithOnlyPrivateConstructorsShouldBeFinal(final Object object) {
this(object.toString());
}
private ClassWithOnlyPrivateConstructorsShouldBeFinal(final String string) {
super();
setString(string);
}
public final void setString(final String string) {
this.string = string;
}
public String getString() {
return string;
}
}
]]></code>
</test-code>

View File

@ -1407,7 +1407,9 @@ constructor is called by a inner class.
TypeDeclaration[count(../TypeDeclaration) = 1]/ClassOrInterfaceDeclaration
[@Final = 'false']
[count(./ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/ConstructorDeclaration[@Private = 'true']) >= 1 ]
[count(./ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/ConstructorDeclaration[@Public = 'true']) = 0 ]
[count(./ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/ConstructorDeclaration[@Public = 'true']) +
count(./ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/ConstructorDeclaration[@Protected = 'true']) +
count(./ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/ConstructorDeclaration[@PackagePrivate = 'true']) = 0 ]
[not(.//ClassOrInterfaceDeclaration)]
]]></value>
</property>