forked from phoedos/pmd
#1376 CompareObjectsWithEquals fails for type annotated method parameter
This commit is contained in:
@ -78,11 +78,8 @@ 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);
|
||||
ASTReferenceType type0 = ((Node) nd0.getAccessNodeParent()).getFirstDescendantOfType(ASTReferenceType.class);
|
||||
ASTReferenceType type1 = ((Node) nd1.getAccessNodeParent()).getFirstDescendantOfType(ASTReferenceType.class);
|
||||
// skip, if it is an enum
|
||||
if (type0.getType() != null && type0.getType().equals(type1.getType()) && type0.getType().isEnum()) {
|
||||
return data;
|
||||
|
@ -189,4 +189,16 @@ class SomeObject {
|
||||
*/
|
||||
]]></code>
|
||||
</test-code>
|
||||
<test-code>
|
||||
<description>#1376 CompareObjectsWithEquals fails for type annotated method parameter</description>
|
||||
<expected-problems>1</expected-problems>
|
||||
<code><![CDATA[
|
||||
public class CompareWithEqualsTest {
|
||||
public static boolean test(@Nullable Object a, Object b)
|
||||
{
|
||||
return a == b;
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
</test-data>
|
||||
|
@ -19,5 +19,6 @@
|
||||
* [#1366](https://sourceforge.net/p/pmd/bugs/1366/): UselessParentheses false positive on multiple equality operators
|
||||
* [#1372](https://sourceforge.net/p/pmd/bugs/1372/): False Negative for CloseResource rule.
|
||||
* [#1375](https://sourceforge.net/p/pmd/bugs/1375/): CloseResource not detected properly
|
||||
* [#1376}(https://sourceforge.net/p/pmd/bugs/1376/): CompareObjectsWithEquals fails for type annotated method parameter
|
||||
|
||||
**API Changes:**
|
||||
|
Reference in New Issue
Block a user