diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/AccessorClassGenerationRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/AccessorClassGenerationRule.java index f0f8095fc1..cad0f0472b 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/AccessorClassGenerationRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/AccessorClassGenerationRule.java @@ -72,19 +72,22 @@ public class AccessorClassGenerationRule extends AbstractJavaRule { final List constructors = privateConstructors.get(type.getImage()); if (constructors != null) { - final ASTArguments callArguments = (ASTArguments) node.jjtGetChild(1); - final ClassScope enclosingScope = node.getScope().getEnclosingScope(ClassScope.class); - - for (final ASTConstructorDeclaration cd : constructors) { - // Are we within the same class scope? - if (cd.getScope().getEnclosingScope(ClassScope.class) == enclosingScope) { - break; - } - - if (cd.getParameterCount() == callArguments.getArgumentCount()) { - // TODO : Check types - addViolation(data, node); - break; + final ASTArguments callArguments = node.getFirstChildOfType(ASTArguments.class); + // Is this really a constructor call and not an array? + if (callArguments != null) { + final ClassScope enclosingScope = node.getScope().getEnclosingScope(ClassScope.class); + + for (final ASTConstructorDeclaration cd : constructors) { + // Are we within the same class scope? + if (cd.getScope().getEnclosingScope(ClassScope.class) == enclosingScope) { + break; + } + + if (cd.getParameterCount() == callArguments.getArgumentCount()) { + // TODO : Check types + addViolation(data, node); + break; + } } } } diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/AccessorClassGeneration.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/AccessorClassGeneration.xml index cbe0fe1446..763a734879 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/AccessorClassGeneration.xml +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/AccessorClassGeneration.xml @@ -128,6 +128,26 @@ public class Example extends View { } }); } +} + ]]> + + + + 0 + diff --git a/src/site/markdown/overview/changelog.md b/src/site/markdown/overview/changelog.md index 34115cd45f..546f6eb028 100644 --- a/src/site/markdown/overview/changelog.md +++ b/src/site/markdown/overview/changelog.md @@ -453,6 +453,7 @@ You need to use this, if you have a large project with many files, and you hit t * [#275](https://github.com/pmd/pmd/issues/275): \[java] FinalFieldCouldBeStatic: Constant in @interface incorrectly reported as "could be made static" * [#282](https://github.com/pmd/pmd/issues/282): \[java] UnnecessaryLocalBeforeReturn false positive when cloning Maps * [#291](https://github.com/pmd/pmd/issues/291): \[java] Improve quality of AccessorClassGeneration + * [#352](https://github.com/pmd/pmd/issues/352): \[java] AccessorClassGeneration throws ClassCastException when seeing array construction * java-imports * [#338](https://github.com/pmd/pmd/issues/338): \[java] False positive on DontImportJavaLang when importing java.lang.ProcessBuilder * [#339](https://github.com/pmd/pmd/issues/339): \[java] False positive on DontImportJavaLang when importing Java 7's java.lang.invoke.MethodHandles