Merge pull request #1354 from adangel/issue-1352

[java] MissingSerialVersionUID false-negative with abstract classes
This commit is contained in:
Juan Martín Sotuyo Dodero authored and GitHub committed 2018-09-22 04:39:10 -03:00
commit 7805868f72
3 files changed
+22 -5

No files matched your search

+8
View File
@@ -63,6 +63,13 @@ until the next major release but it is recommended to stop using them.
`.internal` packages or hidden will be tagged `@InternalApi` before that major release, and
the breaking API changes will be performed in 7.0.0.
#### Modified Rules
* The rule {% rule java/errorprone/MissingSerialVersionUID %} (`java-errorprone`) has been modified
in order to recognize also missing `serialVersionUID` fields in abstract classes, if they are serializable.
Each individual class in the inheritance chain needs an own serialVersionUID field. See also [Should an abstract class have a serialVersionUID](https://stackoverflow.com/questions/893259/should-an-abstract-class-have-a-serialversionuid).
This change might lead to additional violations in existing code bases.
### Fixed Issues
* apex-bestpractices
@@ -72,6 +79,7 @@ the breaking API changes will be performed in 7.0.0.
* [#1334](https://github.com/pmd/pmd/issues/1334): \[java] LinguisticNaming should support AtomicBooleans
* java-errorprone
* [#1350](https://github.com/pmd/pmd/issues/1350): \[java] MissingSerialVersionUID false-positive on interfaces
* [#1352](https://github.com/pmd/pmd/issues/1352): \[java] MissingSerialVersionUID false-negative with abstract classes
* java-performance
* [#1325](https://github.com/pmd/pmd/issues/1325): \[java] False positive in ConsecutiveLiteralAppends
@@ -2294,6 +2294,8 @@ public void bar(int status) {
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#missingserialversionuid">
<description>
Serializable classes should provide a serialVersionUID field.
The serialVersionUID field is also needed for abstract base classes. Each individual class in the inheritance
chain needs an own serialVersionUID field. See also [Should an abstract class have a serialVersionUID](https://stackoverflow.com/questions/893259/should-an-abstract-class-have-a-serialversionuid).
</description>
<priority>3</priority>
<properties>
@@ -2301,7 +2303,6 @@ Serializable classes should provide a serialVersionUID field.
<value>
<![CDATA[
//ClassOrInterfaceDeclaration
[@Abstract = 'false']
[@Interface = 'false']
[count(ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration
/FieldDeclaration/VariableDeclarator/VariableDeclaratorId[@Image='serialVersionUID']) = 0]
@@ -67,16 +67,24 @@ public interface Foo implements Bar{
]]></code>
</test-code>
<test-code>
<description><![CDATA[
abstract case
]]></description>
<expected-problems>0</expected-problems>
<description>abstract case, see #1352</description>
<expected-problems>1</expected-problems>
<code><![CDATA[
import java.io.Serializable;
public abstract class Foo implements Serializable {
}
]]></code>
</test-code>
<test-code>
<description>inherited abstract case</description>
<expected-problems>1</expected-problems>
<code><![CDATA[
package net.sourceforge.pmd.lang.java.rule.errorprone;
public abstract class AbstractMissingSerialVersionUIDTest extends MissingSerialVersionUIDBase {
// no serial version UID
}
]]></code>
</test-code>
<test-code>
<description><![CDATA[
@SuppressWarnings("serial")