pmd: fix #977 MisplacedNullCheck makes false positives

This commit is contained in:
Andreas Dangel committed 2013-03-16 19:17:48 +01:00
1 parent 72d07a8e7e
commit 8ea9d29f31
3 files changed
+29 -7

No files matched your search

+1
View File
@@ -15,6 +15,7 @@ New Java rule:
????? ??, 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
+15 -7
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>
@@ -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>