From ef243584952640084a4682594203d97826f8d501 Mon Sep 17 00:00:00 2001 From: Xavier Le Vourch Date: Sat, 27 Oct 2007 17:54:00 +0000 Subject: [PATCH] Bug fix: state info in BooleanInstantiation rule needs to be reset for each file (stress test on jdk src wasn't giving consistent results depending on which thread was processing files as each thread has a different set of Rule objects) git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@5596 51baf565-9d33-0410-a72c-fc3788e3496d --- .../pmd/rules/basic/xml/BooleanInstantiation.xml | 11 +++++++++++ .../pmd/rules/basic/BooleanInstantiation.java | 10 +++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) 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