diff --git a/pmd/regress/test/net/sourceforge/pmd/rules/basic/xml/BooleanInstantiation.xml b/pmd/regress/test/net/sourceforge/pmd/rules/basic/xml/BooleanInstantiation.xml index 98ce6f0941..bc272936f1 100644 --- a/pmd/regress/test/net/sourceforge/pmd/rules/basic/xml/BooleanInstantiation.xml +++ b/pmd/regress/test/net/sourceforge/pmd/rules/basic/xml/BooleanInstantiation.xml @@ -144,6 +144,17 @@ public class Foo { public void Bar() { Boolean b = new Boolean("true"); } +} + ]]> + + + + 1 + diff --git a/pmd/src/net/sourceforge/pmd/rules/basic/BooleanInstantiation.java b/pmd/src/net/sourceforge/pmd/rules/basic/BooleanInstantiation.java index b0b60d517e..b68a7a9dfb 100644 --- a/pmd/src/net/sourceforge/pmd/rules/basic/BooleanInstantiation.java +++ b/pmd/src/net/sourceforge/pmd/rules/basic/BooleanInstantiation.java @@ -5,6 +5,7 @@ import net.sourceforge.pmd.ast.ASTAllocationExpression; import net.sourceforge.pmd.ast.ASTArrayDimsAndInits; import net.sourceforge.pmd.ast.ASTBooleanLiteral; import net.sourceforge.pmd.ast.ASTClassOrInterfaceType; +import net.sourceforge.pmd.ast.ASTCompilationUnit; import net.sourceforge.pmd.ast.ASTImportDeclaration; import net.sourceforge.pmd.ast.ASTLiteral; import net.sourceforge.pmd.ast.ASTName; @@ -34,9 +35,12 @@ public class BooleanInstantiation extends AbstractRule { */ private boolean customBoolean; - public BooleanInstantiation() { - customBoolean = false; - } + public Object visit(ASTCompilationUnit decl,Object data) { + // customBoolean needs to be reset for each new file + customBoolean = false; + + return super.visit(decl, data); + } public Object visit(ASTImportDeclaration decl,Object data) { // If the import actually import a Boolean class that overrides java.lang.Boolean