From 443f73b744ee94031361a8e2e23c3a8f24bc4cd9 Mon Sep 17 00:00:00 2001 From: oowekyala Date: Mon, 14 Aug 2017 00:18:34 +0200 Subject: [PATCH 1/2] Fix #388 --- .../resources/rulesets/java/controversial.xml | 2 +- .../xml/AvoidLiteralsInIfCondition.xml | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/pmd-java/src/main/resources/rulesets/java/controversial.xml b/pmd-java/src/main/resources/rulesets/java/controversial.xml index 779217c9f0..5c59d8f486 100644 --- a/pmd-java/src/main/resources/rulesets/java/controversial.xml +++ b/pmd-java/src/main/resources/rulesets/java/controversial.xml @@ -681,7 +681,7 @@ More exceptions can be defined with the property "ignoreMagicNumbers". //IfStatement/Expression/*/PrimaryExpression/PrimaryPrefix/Literal [not(NullLiteral)] [not(BooleanLiteral)] -[empty(index-of(tokenize($ignoreMagicNumbers, ','), @Image))] +[empty(index-of(tokenize($ignoreMagicNumbers, '\s*,\s*'), @Image))] ]]> diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/controversial/xml/AvoidLiteralsInIfCondition.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/controversial/xml/AvoidLiteralsInIfCondition.xml index 57a5ab6798..9da329bc6d 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/controversial/xml/AvoidLiteralsInIfCondition.xml +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/controversial/xml/AvoidLiteralsInIfCondition.xml @@ -74,4 +74,19 @@ public class Foo { } ]]> + + #388 False positive due to space in property list + 0 + + + + From 2fdb8de3f2a7b4c8f2bd582cbeb00459d363c49b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Mart=C3=ADn=20Sotuyo=20Dodero?= Date: Sat, 9 Sep 2017 18:55:29 -0300 Subject: [PATCH 2/2] Update changelog, refs #598 --- 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 d92379bfaa..b88142a5cf 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -166,6 +166,7 @@ All existing rules have been updated to reflect these changes. If you have custo * java-comments * [#536](https://github.com/pmd/pmd/issues/536): \[java] CommentDefaultAccessModifierRule ignores constructors * java-controversial + * [#388](https://github.com/pmd/pmd/issues/388): \[java] controversial.AvoidLiteralsInIfCondition 0.0 false positive * [#408](https://github.com/pmd/pmd/issues/408): \[java] DFA not analyzing asserts * [#537](https://github.com/pmd/pmd/issues/537): \[java] UnnecessaryParentheses fails to detect obvious scenario * java-design @@ -283,3 +284,4 @@ All existing rules have been updated to reflect these changes. If you have custo * [#581](https://github.com/pmd/pmd/pull/581): \[java] Relax AbstractClassWithoutAnyMethod when class is annotated by @AutoValue - [Niklas Baudy](https://github.com/vanniktech) * [#583](https://github.com/pmd/pmd/pull/583): \[java] Documentation about writing metrics - [Clément Fournier](https://github.com/oowekyala) * [#585](https://github.com/pmd/pmd/pull/585): \[java] Moved NcssCountRule to codesize.xml - [Clément Fournier](https://github.com/oowekyala) +* [#598](https://github.com/pmd/pmd/pull/598): \[java] Fix #388: controversial.AvoidLiteralsInIfCondition 0.0 false positive - [Clément Fournier](https://github.com/oowekyala)