forked from phoedos/pmd
pmd: fixed #1028 False-positive: Compare objects with equals for Enums
This commit is contained in:
parent
d557ed9c01
commit
ffac9894c9
@ -5,6 +5,7 @@ Fixed bug 913: SignatureDeclareThrowsException is raised twice
|
||||
Fixed bug 1012: False positive: Useless parentheses.
|
||||
Fixed bug 1020: Parsing Error
|
||||
Fixed bug 1026: PMD doesn't handle 'value =' in SuppressWarnings annotation
|
||||
Fixed bug 1028: False-positive: Compare objects with equals for Enums
|
||||
Fixed bug 1037: Facing a showstopper issue in PMD Report Class (report listeners)
|
||||
Fixed bug 1043: node.getEndLine() always returns 0 (ECMAscript)
|
||||
Fixed bug 1044: Unknown option: -excludemarker
|
||||
|
@ -5,6 +5,7 @@ import net.sourceforge.pmd.lang.java.ast.ASTAllocationExpression;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTEqualityExpression;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTInitializer;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTName;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTReferenceType;
|
||||
import net.sourceforge.pmd.lang.java.rule.AbstractJavaRule;
|
||||
import net.sourceforge.pmd.lang.java.symboltable.VariableNameDeclaration;
|
||||
|
||||
@ -65,6 +66,14 @@ public class CompareObjectsWithEqualsRule extends AbstractJavaRule {
|
||||
}
|
||||
|
||||
if (nd0.isReferenceType() && nd1.isReferenceType()) {
|
||||
|
||||
ASTReferenceType type0 = (ASTReferenceType)((Node) nd0.getAccessNodeParent()).jjtGetChild(0).jjtGetChild(0);
|
||||
ASTReferenceType type1 = (ASTReferenceType)((Node) nd1.getAccessNodeParent()).jjtGetChild(0).jjtGetChild(0);
|
||||
// skip, if it is an enum
|
||||
if (type0.getType() != null && type0.getType().equals(type1.getType()) && type0.getType().isEnum()) {
|
||||
return data;
|
||||
}
|
||||
|
||||
addViolation(data, node);
|
||||
}
|
||||
}
|
||||
|
@ -136,5 +136,18 @@ public class Foo {
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
||||
<test-code>
|
||||
<description>#1028 False-positive: Compare objects with equals for Enums</description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
import java.math.RoundingMode;
|
||||
public class Test {
|
||||
void doEnums() {
|
||||
RoundingMode mode1 = determineFirstMode();
|
||||
RoundingMode mode2 = determineSecondMode();
|
||||
if (mode1 == mode2) {}
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
</test-data>
|
||||
|
Loading…
x
Reference in New Issue
Block a user