pmd: fix #977 MisplacedNullCheck makes false positives

This commit is contained in:
Andreas Dangel 2013-03-16 19:17:48 +01:00
parent 30af4f6381
commit 4e5ca16990
3 changed files with 29 additions and 7 deletions

View File

@ -1,5 +1,6 @@
????? ??, 2013 - 5.0.3:
Fixed bug 977: MisplacedNullCheck makes false positives
Fixed bug 984: Cyclomatic complexity should treat constructors like methods
Fixed bug 985: Suppressed methods shouldn't affect avg CyclomaticComplexity
Fixed bug 992: Class java.beans.Statement triggered in CloseResource rule

View File

@ -386,13 +386,21 @@ Either the check is useless (the variable will never be "null") or it is incorre
<![CDATA[
//Expression
/*[self::ConditionalOrExpression or self::ConditionalAndExpression]
/descendant::PrimaryExpression/PrimaryPrefix
/Name[starts-with(@Image,
concat(ancestor::PrimaryExpression/following-sibling::EqualityExpression
[./PrimaryExpression/PrimaryPrefix/Literal/NullLiteral]
/PrimaryExpression/PrimaryPrefix
/Name[count(../../PrimarySuffix)=0]/@Image,"."))
]
/descendant::PrimaryExpression/PrimaryPrefix
/Name[starts-with(@Image,
concat(ancestor::PrimaryExpression/following-sibling::EqualityExpression
[./PrimaryExpression/PrimaryPrefix/Literal/NullLiteral]
/PrimaryExpression/PrimaryPrefix
/Name[count(../../PrimarySuffix)=0]/@Image,".")
)
]
[count(ancestor::ConditionalAndExpression/EqualityExpression
[@Image='!=']
[./PrimaryExpression/PrimaryPrefix/Literal/NullLiteral]
[starts-with(following-sibling::*/PrimaryExpression/PrimaryPrefix/Name/@Image,
concat(./PrimaryExpression/PrimaryPrefix/Name/@Image, '.'))]
) = 0
]
]]>
</value>
</property>

View File

@ -69,4 +69,17 @@ public class Foo {
}
]]></code>
</test-code>
<test-code>
<description>#977 MisplacedNullCheck makes false positives</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class Test {
public void method(final String value,final String oldValue) {
if ((value != null && !value.equals(oldValue)) || value == null) {
// Do something
}
}
}
]]></code>
</test-code>
</test-data>