diff --git a/pmd/etc/changelog.txt b/pmd/etc/changelog.txt index 2e4f937b7e..f3d8ad0433 100644 --- a/pmd/etc/changelog.txt +++ b/pmd/etc/changelog.txt @@ -1,5 +1,6 @@ ???? ??, 2012 - 5.0.2: +Fixed bug 1012: False positive: Useless parentheses. Fixed bug 1026: PMD doesn't handle 'value =' in SuppressWarnings annotation Fixed bug 1037: Facing a showstopper issue in PMD Report Class (report listeners) Fixed bug 1043: node.getEndLine() always returns 0 (ECMAscript) diff --git a/pmd/src/main/resources/rulesets/java/unnecessary.xml b/pmd/src/main/resources/rulesets/java/unnecessary.xml index f6a82f2d15..87ef218961 100644 --- a/pmd/src/main/resources/rulesets/java/unnecessary.xml +++ b/pmd/src/main/resources/rulesets/java/unnecessary.xml @@ -225,7 +225,8 @@ public class Test { //Expression/ConditionalAndExpression/PrimaryExpression/PrimaryPrefix/Expression[ count(*)=1 and count(./CastExpression)=0 and - count(./EqualityExpression/MultiplicativeExpression)=0] + count(./EqualityExpression/MultiplicativeExpression)=0 and + count(./ConditionalOrExpression)=0] | //Expression/ConditionalOrExpression/PrimaryExpression/PrimaryPrefix/Expression[ count(*)=1 and @@ -237,7 +238,10 @@ public class Test { count(./CastExpression)=0 and count(./EqualityExpression)=0] | -//Expression/AdditiveExpression/PrimaryExpression/PrimaryPrefix/Expression[count(*)=1 and not(./CastExpression) and not(./ConditionalExpression)] +//Expression/AdditiveExpression[not(./PrimaryExpression/PrimaryPrefix/Literal[@StringLiteral = 'true'])]/PrimaryExpression/PrimaryPrefix/Expression[ + count(*)=1 and + not(./CastExpression) and + not(./ConditionalExpression)] | //Expression/EqualityExpression/PrimaryExpression/PrimaryPrefix/Expression[ count(*)=1 and diff --git a/pmd/src/test/java/net/sourceforge/pmd/lang/java/rule/unnecessary/UnnecessaryRulesTest.java b/pmd/src/test/java/net/sourceforge/pmd/lang/java/rule/unnecessary/UnnecessaryRulesTest.java index 10e5707d51..8847c14761 100644 --- a/pmd/src/test/java/net/sourceforge/pmd/lang/java/rule/unnecessary/UnnecessaryRulesTest.java +++ b/pmd/src/test/java/net/sourceforge/pmd/lang/java/rule/unnecessary/UnnecessaryRulesTest.java @@ -20,7 +20,7 @@ public class UnnecessaryRulesTest extends SimpleAggregatorTst { addRule(RULESET, "UnusedNullCheckInEquals"); addRule(RULESET, "UselessOverridingMethod"); addRule(RULESET, "UselessOperationOnImmutable"); - addRule(RULESET, "UselessParentheses"); + addRule(RULESET, "UselessParentheses"); } public static junit.framework.Test suite() { diff --git a/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/unnecessary/xml/UselessParentheses.xml b/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/unnecessary/xml/UselessParentheses.xml index 5dc93cb462..48e8b181b2 100644 --- a/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/unnecessary/xml/UselessParentheses.xml +++ b/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/unnecessary/xml/UselessParentheses.xml @@ -177,6 +177,22 @@ public class Test { int dayCount = 4; String description = dayCount + " " + (dayCount == 1 ? oneDay : moreDays); } +} + ]]> + + + #1012 False positive: Useless parentheses. + 0 +