diff --git a/pmd/etc/changelog.txt b/pmd/etc/changelog.txt index 8ad872e8f4..e153082e82 100644 --- a/pmd/etc/changelog.txt +++ b/pmd/etc/changelog.txt @@ -6,6 +6,7 @@ Fixed bug 2606609 - False "UnusedImports" positive in package-info.java Fixed bug 2645268 - ClassCastException in UselessOperationOnImmutable.getDeclaration New rule: + Controversial : AvoidLiteralsInIfCondition (patch 2591627) StrictExceptions : AvoidCatchingGenericException February 08, 2009 - 4.2.5: diff --git a/pmd/regress/test/net/sourceforge/pmd/rules/controversial/ControversialRulesTest.java b/pmd/regress/test/net/sourceforge/pmd/rules/controversial/ControversialRulesTest.java index 4198ff3b6f..3d7c860ad5 100644 --- a/pmd/regress/test/net/sourceforge/pmd/rules/controversial/ControversialRulesTest.java +++ b/pmd/regress/test/net/sourceforge/pmd/rules/controversial/ControversialRulesTest.java @@ -10,6 +10,7 @@ public class ControversialRulesTest extends SimpleAggregatorTst { public void setUp() { addRule("controversial", "AssignmentInOperand"); addRule("controversial", "AvoidFinalLocalVariable"); + addRule("controversial", "AvoidLiteralsInIfCondition"); addRule("controversial", "AvoidUsingNativeCode"); addRule("controversial", "AvoidUsingShortType"); addRule("controversial", "AvoidUsingVolatile"); diff --git a/pmd/regress/test/net/sourceforge/pmd/rules/controversial/xml/AvoidLiteralsInIfCondition.xml b/pmd/regress/test/net/sourceforge/pmd/rules/controversial/xml/AvoidLiteralsInIfCondition.xml new file mode 100644 index 0000000000..b075a5318a --- /dev/null +++ b/pmd/regress/test/net/sourceforge/pmd/rules/controversial/xml/AvoidLiteralsInIfCondition.xml @@ -0,0 +1,28 @@ + + + + basic test + 1 + + + + basic test, part2 + 0 + + + \ No newline at end of file diff --git a/pmd/rulesets/controversial.xml b/pmd/rulesets/controversial.xml index 5c4621a98c..e00673ab0d 100644 --- a/pmd/rulesets/controversial.xml +++ b/pmd/rulesets/controversial.xml @@ -682,6 +682,36 @@ public void doSomething() { // Explicit gc call ! Runtime.getRuntime().gc(); } } + + + Avoid using hard coded literals in conditional statements, declare those as static variables or private members. + + 3 + + + + + + + + + + + +