From 348a9972e6024b77678c5ea69d7d8dade10efb71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Sun, 2 Jun 2019 09:26:13 +0200 Subject: [PATCH 1/3] Fix #1853 false positive in NonStaticInitializer --- .../resources/category/java/errorprone.xml | 3 +- .../errorprone/xml/NonStaticInitializer.xml | 67 ++++++++++++++++--- 2 files changed, 61 insertions(+), 9 deletions(-) diff --git a/pmd-java/src/main/resources/category/java/errorprone.xml b/pmd-java/src/main/resources/category/java/errorprone.xml index 7e59da309f..19e5edc60a 100644 --- a/pmd-java/src/main/resources/category/java/errorprone.xml +++ b/pmd-java/src/main/resources/category/java/errorprone.xml @@ -2505,10 +2505,11 @@ confusing. 3 + diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml/NonStaticInitializer.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml/NonStaticInitializer.xml index cb058c6169..235904d78b 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml/NonStaticInitializer.xml +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml/NonStaticInitializer.xml @@ -4,25 +4,76 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pmd.sourceforge.net/rule-tests http://pmd.sourceforge.net/rule-tests_1_0_0.xsd"> - + bad 1 + ]]> + - + static initializers are OK 0 + ]]> + + + + Allowed in anonymous classes + 0 + + + + + Flag in local class + 1 + 3 + + + + + Allowed in enum constant + 1 + 7 + + + From 6b3ccdf0693945e9077c8c1699b230347328eebd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Mon, 24 Jun 2019 12:11:12 +0200 Subject: [PATCH 2/3] Add a test case --- .../errorprone/xml/NonStaticInitializer.xml | 32 ++++++++++++++++--- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml/NonStaticInitializer.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml/NonStaticInitializer.xml index 235904d78b..d66001be47 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml/NonStaticInitializer.xml +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml/NonStaticInitializer.xml @@ -1,8 +1,7 @@ - + bad 1 @@ -23,7 +22,6 @@ public class Foo { ]]> - Allowed in anonymous classes 0 @@ -72,6 +70,30 @@ public enum Foo { { setCycleDuration(Duration.millis(1200)); } +} + ]]> + + + + Flag in nested local class + 1 + 7 + From 79ae09638f9fcf10a6c3f93a134a79ebf0666ecf Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 28 Jun 2019 20:58:56 +0200 Subject: [PATCH 3/3] Update release notes, fixes #1853 --- docs/pages/release_notes.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index 6f8569d6b5..0629d1b5dc 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -18,6 +18,8 @@ This is a {{ site.pmd.release_type }} release. * java * [#1848](https://github.com/pmd/pmd/issues/1848): \[java] Local classes should preserve their modifiers +* java-errorprone + * [#1853](https://github.com/pmd/pmd/issues/1853): \[java] False positive for NonStaticInitializer in anonymous class ### API Changes