forked from phoedos/pmd
Merge branch 'pr-1258'
This commit is contained in:
@ -2277,6 +2277,7 @@ public void bar(int status) {
|
||||
since="3.0"
|
||||
message="Classes implementing Serializable should set a serialVersionUID"
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
typeResolution="true"
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#missingserialversionuid">
|
||||
<description>
|
||||
Serializable classes should provide a serialVersionUID field.
|
||||
@ -2287,16 +2288,10 @@ Serializable classes should provide a serialVersionUID field.
|
||||
<value>
|
||||
<![CDATA[
|
||||
//ClassOrInterfaceDeclaration
|
||||
[
|
||||
count(ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration
|
||||
/FieldDeclaration/VariableDeclarator/VariableDeclaratorId[@Image='serialVersionUID']) = 0
|
||||
and
|
||||
count(ImplementsList
|
||||
[ClassOrInterfaceType/@Image='Serializable'
|
||||
or ClassOrInterfaceType/@Image='java.io.Serializable']) =1
|
||||
and
|
||||
@Abstract = 'false'
|
||||
]
|
||||
[@Abstract = 'false']
|
||||
[count(ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration
|
||||
/FieldDeclaration/VariableDeclarator/VariableDeclaratorId[@Image='serialVersionUID']) = 0]
|
||||
[(ImplementsList | ExtendsList)/ClassOrInterfaceType[typeIs('java.io.Serializable')]]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
|
@ -0,0 +1,14 @@
|
||||
/**
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
package net.sourceforge.pmd.lang.java.rule.errorprone;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* This class is used for a test case for the rule MissingSerialVersionUID.
|
||||
*/
|
||||
public class MissingSerialVersionUIDBase implements Serializable {
|
||||
private static final long serialVersionUID = 1234567L;
|
||||
}
|
@ -88,4 +88,15 @@ public class Foo implements Serializable {
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
||||
<test-code>
|
||||
<description>#1078 [java] MissingSerialVersionUID rule does not seem to catch inherited classes</description>
|
||||
<expected-problems>1</expected-problems>
|
||||
<code><![CDATA[
|
||||
package net.sourceforge.pmd.lang.java.rule.errorprone;
|
||||
public class MissingSerialVersionUIDTest extends MissingSerialVersionUIDBase {
|
||||
// ... no serialVersionUID value defined ...
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
</test-data>
|
||||
|
Reference in New Issue
Block a user