diff --git a/pmd/etc/changelog.txt b/pmd/etc/changelog.txt index c4e63a76aa..681160a1f8 100644 --- a/pmd/etc/changelog.txt +++ b/pmd/etc/changelog.txt @@ -19,7 +19,7 @@ Fixed bug 1435751 - Added encoding type of UTF-8 to the CPD XML file. Fixed bug 1441539 - ConsecutiveLiteralAppends no longer flags appends() involving method calls. Fixed bug 1339470 - PMD no longer fails to parse certain non-static initializers. Fixed bug 1425772 - PMD no longer fails with errors in ASTFieldDeclaration when parsing some JDK 1.5 code. -Fixed bug 1448123 - AvoidFieldNameMatchingTypeName no longer errors out on enumerations. +Fixed bug 1448123 - AvoidFieldNameMatchingTypeName and AvoidFieldNameMatchingMethodName no longer error out on enumerations. Fixed bug 1444654 - migrating_to_14 and migrating_to_15 no longer refer to rule tests. Fixed bug 1445231 - TestClassWithoutTestCases: no longer flags abstract classes. Fixed bug 1445765 - PMD no longer uses huge amounts of memory. However, you need to use RuleViolation.getBeginLine(); RuleViolation.getNode() is no more. diff --git a/pmd/src/net/sourceforge/pmd/rules/AvoidFieldNameMatchingMethodName.java b/pmd/src/net/sourceforge/pmd/rules/AvoidFieldNameMatchingMethodName.java index 9bc78e84ff..0b23c94971 100644 --- a/pmd/src/net/sourceforge/pmd/rules/AvoidFieldNameMatchingMethodName.java +++ b/pmd/src/net/sourceforge/pmd/rules/AvoidFieldNameMatchingMethodName.java @@ -26,15 +26,17 @@ public class AvoidFieldNameMatchingMethodName extends AbstractRule { if (varName != null) { varName = varName.toLowerCase(); ASTClassOrInterfaceDeclaration cl = (ASTClassOrInterfaceDeclaration) node.getFirstParentOfType(ASTClassOrInterfaceDeclaration.class); - List methods = cl.findChildrenOfType(ASTMethodDeclaration.class); - if (!methods.isEmpty()) { - for (Iterator it = methods.iterator(); it.hasNext();) { - ASTMethodDeclaration m = (ASTMethodDeclaration) it.next(); - //Make sure we are comparing fields and methods inside same type - if (fieldDeclaringType.equals(getDeclaringType(m))) { - String n = m.getMethodName(); - if (varName.equals(n.toLowerCase())) { - addViolation(data, node); + if (cl != null) { + List methods = cl.findChildrenOfType(ASTMethodDeclaration.class); + if (!methods.isEmpty()) { + for (Iterator it = methods.iterator(); it.hasNext();) { + ASTMethodDeclaration m = (ASTMethodDeclaration) it.next(); + //Make sure we are comparing fields and methods inside same type + if (fieldDeclaringType.equals(getDeclaringType(m))) { + String n = m.getMethodName(); + if (varName.equals(n.toLowerCase())) { + addViolation(data, node); + } } } }