diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/basic/BooleanInstantiationRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/basic/BooleanInstantiationRule.java index c5091dd89f..032db19a4d 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/basic/BooleanInstantiationRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/basic/BooleanInstantiationRule.java @@ -3,6 +3,7 @@ */ package net.sourceforge.pmd.lang.java.rule.basic; +import net.sourceforge.pmd.lang.ast.Node; import net.sourceforge.pmd.lang.java.ast.ASTAllocationExpression; import net.sourceforge.pmd.lang.java.ast.ASTArrayDimsAndInits; import net.sourceforge.pmd.lang.java.ast.ASTBooleanLiteral; @@ -63,7 +64,9 @@ public class BooleanInstantiationRule extends AbstractJavaRule { if (node.hasDescendantOfType(ASTArrayDimsAndInits.class)) { return super.visit(node, data); } - if (TypeHelper.isA((ASTClassOrInterfaceType) node.jjtGetChild(0), Boolean.class)) { + + Node n1 = node.getFirstChildOfType(ASTClassOrInterfaceType.class); + if (TypeHelper.isA((ASTClassOrInterfaceType) n1, Boolean.class)) { super.addViolation(data, node); return data; } diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/basic/xml/BooleanInstantiation.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/basic/xml/BooleanInstantiation.xml index bc272936f1..f6fe35d2cc 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/basic/xml/BooleanInstantiation.xml +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/basic/xml/BooleanInstantiation.xml @@ -158,4 +158,16 @@ public class Foo { } ]]> + + + #1533 [java] BooleanInstantiation: ClassCastException with Annotation + 0 + + diff --git a/src/site/markdown/overview/changelog.md b/src/site/markdown/overview/changelog.md index 7f54fd4429..a1e157f24a 100644 --- a/src/site/markdown/overview/changelog.md +++ b/src/site/markdown/overview/changelog.md @@ -15,11 +15,14 @@ * [#106](https://github.com/pmd/pmd/pull/106): \[java] CPD: Keep constructor names under ignoreIdentifiers * [#107](https://github.com/pmd/pmd/pull/107): \[groovy] Initial support for CPD Groovy * [#110](https://github.com/pmd/pmd/pull/110): \[java] Fix parser error (issue 1530) +* [#111](https://github.com/pmd/pmd/pull/111): \[java] Fix BooleanInstantiationRule for Java 8 **Bugfixes:** * Java * [#1530](https://sourceforge.net/p/pmd/bugs/1530/): \[java] Parser exception on Java code +* java-basic/BooleanInstantiation + * [#1533](https://sourceforge.net/p/pmd/bugs/1533/): \[java] BooleanInstantiation: ClassCastException with Annotation * java-comments * [#1522](https://sourceforge.net/p/pmd/bugs/1522/): \[java] CommentRequired: false positive * java-imports/UnusedImports