Fixed bug 1242544 - SimplifyConditional no longer flags null checks that precede an instanceof involving an array dereference.
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@3728 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -14,7 +14,8 @@ Fixed bug 1228589 - DoubleCheckedLocking and ExceptionSignatureDeclaration no lo
|
||||
Fixed bug 1235299 - NullAssignment no longer flags null equality comparisons in ternary expressions.
|
||||
Fixed bug 1235300 - NullAssignment no longer flags assignments to final fields.
|
||||
Fixed bug 1240201 - The UnnecessaryParentheses message is no longer restricted to return statements.
|
||||
Fixed bug 1242290 - The JDK 1.5 parser no longer chokes on nested enumerations with a constructor.
|
||||
Fixed bug 1242290 - The JDK 1.5 parser no longer chokes on nested enumerations with a constructor.
|
||||
Fixed bug 1242544 - SimplifyConditional no longer flags null checks that precede an instanceof involving an array dereference.
|
||||
Applied patch 1228834 - XPath rules can now use properties to customize rules. Thanks to Wouter Zelle for another great piece of work!
|
||||
Fixed a bug in RuleSetFactory that missed some override cases; thx to Wouter Zelle for the report and a fix.
|
||||
Fixed a bug in the grammar that didn't allow constructors to have type parameters, which couldn't parse some JDK 1.5 constructs.
|
||||
|
@ -10,7 +10,7 @@ public class ASTPrimarySuffixTest extends ParserTst {
|
||||
|
||||
public void testArrayDereference() throws Throwable {
|
||||
Set ops = getNodes(ASTPrimarySuffix.class, TEST1);
|
||||
assertTrue(((ASTPrimarySuffix)(ops.iterator().next())).isArrayDeference());
|
||||
assertTrue(((ASTPrimarySuffix)(ops.iterator().next())).isArrayDereference());
|
||||
}
|
||||
|
||||
public void testArguments() throws Throwable {
|
||||
|
@ -19,6 +19,7 @@ public class SimplifyConditionalTest extends SimpleAggregatorTst{
|
||||
new TestDescriptor(TEST2, "ok", 0, rule),
|
||||
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),
|
||||
});
|
||||
}
|
||||
|
||||
@ -50,4 +51,11 @@ public class SimplifyConditionalTest extends SimpleAggregatorTst{
|
||||
" }" + PMD.EOL +
|
||||
"}";
|
||||
|
||||
private static final String TEST5 =
|
||||
"public class Foo {" + PMD.EOL +
|
||||
" void bar(Object x) {" + PMD.EOL +
|
||||
" if (x != null && x[0] instanceof String) {}" + PMD.EOL +
|
||||
" }" + PMD.EOL +
|
||||
"}";
|
||||
|
||||
}
|
||||
|
@ -1027,7 +1027,7 @@ ConditionalAndExpression
|
||||
[EqualityExpression[@Image='!=']//NullLiteral
|
||||
and
|
||||
InstanceOfExpression
|
||||
[PrimaryExpression
|
||||
[PrimaryExpression[count(PrimarySuffix[@ArrayDereference='true'])=0]
|
||||
//Name/@Image = ancestor::ConditionalAndExpression
|
||||
/EqualityExpression//PrimaryPrefix/Name/@Image]]]
|
||||
]]>
|
||||
|
@ -12,14 +12,14 @@ public class ASTPrimarySuffix extends SimpleNode {
|
||||
}
|
||||
|
||||
private boolean isArguments;
|
||||
private boolean isArrayDeference;
|
||||
private boolean isArrayDereference;
|
||||
|
||||
public void setIsArrayDereference() {
|
||||
isArrayDeference = true;
|
||||
isArrayDereference = true;
|
||||
}
|
||||
|
||||
public boolean isArrayDeference() {
|
||||
return isArrayDeference;
|
||||
public boolean isArrayDereference() {
|
||||
return isArrayDereference;
|
||||
}
|
||||
|
||||
public void setIsArguments() {
|
||||
@ -30,6 +30,15 @@ public class ASTPrimarySuffix extends SimpleNode {
|
||||
return this.isArguments;
|
||||
}
|
||||
|
||||
|
||||
public void dump(String prefix) {
|
||||
String out = "";
|
||||
if (isArrayDereference()) {
|
||||
out += "[";
|
||||
}
|
||||
System.out.println(toString(prefix) + ":" + out);
|
||||
dumpChildren(prefix);
|
||||
}
|
||||
/**
|
||||
* Accept the visitor. *
|
||||
*/
|
||||
|
@ -70,8 +70,7 @@ public class AttributeAxisIterator implements Iterator {
|
||||
|
||||
protected Attribute getAttribute(Node node, Method method)
|
||||
throws IllegalAccessException, InvocationTargetException {
|
||||
String name = method.getName();
|
||||
name = truncateMethodName(name);
|
||||
String name = truncateMethodName(method.getName());
|
||||
Object value = method.invoke(node, EMPTY_OBJ_ARRAY);
|
||||
if (value != null) {
|
||||
if (value instanceof String) {
|
||||
|
@ -44,14 +44,14 @@ public class IdempotentOperations extends AbstractRule {
|
||||
|
||||
if (lhs.jjtGetParent().jjtGetParent().jjtGetNumChildren() > 1) {
|
||||
Node n = lhs.jjtGetParent().jjtGetParent().jjtGetChild(1);
|
||||
if (n instanceof ASTPrimarySuffix && ((ASTPrimarySuffix) n).isArrayDeference()) {
|
||||
if (n instanceof ASTPrimarySuffix && ((ASTPrimarySuffix) n).isArrayDereference()) {
|
||||
return super.visit(node, data);
|
||||
}
|
||||
}
|
||||
|
||||
if (rhs.jjtGetParent().jjtGetParent().jjtGetNumChildren() > 1) {
|
||||
Node n = rhs.jjtGetParent().jjtGetParent().jjtGetChild(1);
|
||||
if (n instanceof ASTPrimarySuffix && ((ASTPrimarySuffix) n).isArguments() || ((ASTPrimarySuffix) n).isArrayDeference()) {
|
||||
if (n instanceof ASTPrimarySuffix && ((ASTPrimarySuffix) n).isArguments() || ((ASTPrimarySuffix) n).isArrayDereference()) {
|
||||
return super.visit(node, data);
|
||||
}
|
||||
}
|
||||
|
@ -43,6 +43,7 @@
|
||||
</subsection>
|
||||
<subsection name="Contributors">
|
||||
<ul>
|
||||
<li>Andriy Rozeluk - Bug report for SimplifyConditional, suggested UnnecessaryLocalBeforeReturn, suggestions for improving BooleanInstantiation, UnnecessaryReturn, AvoidDuplicateLiterals RFEs and bug reports, various other RFEs and thoughtful discussions as well</li>
|
||||
<li>Ernst Reissner - reported JDK 1.5 parsing bug, suggested InstantiationToGetClass, bug reports for UnusedPrivateField/CloseConnectionRule/ConstructorCallsOverridableMethodRule, and bug report and documentation suggestions for UseSingletonRule</li>
|
||||
<li>Wouter Zelle - ProperLogger rule, nifty code to allow variables in XPath rules, externalInfoUrl data for all rules in basic and unusedcode rulesets, some very nifty XSLT, improvements to UseCorrectExceptionLogging, designed and implemented the "externalInfoUrl" feature in the rule definitions, fixed a devious bug in RuleSetFactory, AvoidPrintStackTrace, initial implementation of SimplifyConditional</li>
|
||||
<li>Benoit Xhenseval - suggestion to add elapsed time to XML report, bug report for ImmutableField, many bug reports (with good failure cases!), Ant task patch and bug report, XSLT patch, suggestion for improving XML report</li>
|
||||
@ -51,7 +52,6 @@
|
||||
<li>Kevin Routley - reported Ant task dependency problem, reported problems with RuleSetFactory unit tests</li>
|
||||
<li>Dennis Klemann - noted that errors were missing from text report, reported JDK 1.5 parsing bug with ExceptionSignatureDeclaration, reported fix for pmd.bat problem</li>
|
||||
<li>dvholten - reported several NullAssignment bugs</li>
|
||||
<li>Andriy Rozeluk - Suggested UnnecessaryLocalBeforeReturn, suggestions for improving BooleanInstantiation, UnnecessaryReturn, AvoidDuplicateLiterals RFEs and bug reports, various other RFEs and thoughtful discussions as well</li>
|
||||
<li>Elliotte Rusty Harold - bug report for ConstructorCallsOverridableMethod, suggestion for improving command line interface, mispeling report, suggestion for improving Designer startup script, "how to make a ruleset" documentation suggestions, noticed outdated Xerces jars, script renaming suggestions, UseLocaleWithCaseConversions rule suggestion</li>
|
||||
<li>Wim Deblauwe - reported bug in JUnitTestsShouldContainAsserts, front page and "how to make a ruleset" patches, noted problems with web site rule index, bug report for JUnitTestsShouldContainAsserts, Clover license coordination and implementation, UseCorrectExceptionLogging, coordinated and coded a much nicer asXML() implementation, suggested cleanup of UnusedFormalParameter, Javadoc patch, SystemPrintln bug report, helped get Ant task and CLI squared away with JDK 1.5 params, JDK 1.5-specific bug reports, suggested improvements for ExceptionSignatureDeclaration</li>
|
||||
<li>Pieter Bloemendaal - Found typo in ArrayIsStoredDirectly, bug report for AvoidReassigningParametersRule</li>
|
||||
|
Reference in New Issue
Block a user