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
This commit is contained in:
Xavier Le Vourch
2007-10-27 17:54:00 +00:00
parent d7972f80d1
commit ef24358495
2 changed files with 18 additions and 3 deletions

View File

@ -144,6 +144,17 @@ public class Foo {
public void Bar() {
Boolean b = new Boolean("true");
}
}
]]></code>
</test-code>
<test-code>
<description><![CDATA[
Test for failure after rule with custom Boolean, should report failure if rule reset done correctly
]]></description>
<expected-problems>1</expected-problems>
<code><![CDATA[
public class Foo {
Boolean b = Boolean.valueOf("true");
}
]]></code>
</test-code>

View File

@ -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