forked from phoedos/pmd
Patch to fix false+ in SimplifyConditional; thanks again to Xavier!
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@4515 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -20,6 +20,7 @@ public class SimplifyConditionalTest extends SimpleAggregatorTst {
|
||||
new TestDescriptor(TEST3, "transpose x and null, still bad", 1, rule),
|
||||
new TestDescriptor(TEST4, "conditional or and !(instanceof)", 1, rule),
|
||||
new TestDescriptor(TEST5, "indexing into array is ok", 0, rule),
|
||||
new TestDescriptor(TEST6, "test for null on unrelated object is ok", 0, rule),
|
||||
});
|
||||
}
|
||||
|
||||
@ -58,4 +59,11 @@ public class SimplifyConditionalTest extends SimpleAggregatorTst {
|
||||
" }" + PMD.EOL +
|
||||
"}";
|
||||
|
||||
private static final String TEST6 =
|
||||
"public class Foo {" + PMD.EOL +
|
||||
" void bar(Object x) {" + PMD.EOL +
|
||||
" if (x instanceof String && ((String)x).substring(2) != null) {}" + PMD.EOL +
|
||||
" }" + PMD.EOL +
|
||||
"}";
|
||||
|
||||
}
|
||||
|
@ -1020,7 +1020,7 @@ No need to check for null before an instanceof; the instanceof keyword returns f
|
||||
UnaryExpressionNotPlusMinus
|
||||
[@Image='!']//InstanceOfExpression[PrimaryExpression
|
||||
//Name/@Image = ancestor::ConditionalOrExpression/EqualityExpression
|
||||
//PrimaryPrefix/Name/@Image]]
|
||||
/PrimaryExpression/PrimaryPrefix/Name/@Image]]
|
||||
or
|
||||
ConditionalAndExpression
|
||||
[EqualityExpression[@Image='!=']//NullLiteral
|
||||
@ -1028,7 +1028,7 @@ ConditionalAndExpression
|
||||
InstanceOfExpression
|
||||
[PrimaryExpression[count(PrimarySuffix[@ArrayDereference='true'])=0]
|
||||
//Name/@Image = ancestor::ConditionalAndExpression
|
||||
/EqualityExpression//PrimaryPrefix/Name/@Image]]]
|
||||
/EqualityExpression/PrimaryExpression/PrimaryPrefix/Name/@Image]]]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
|
Reference in New Issue
Block a user