applied patch from Nicolas Dordet to fix False+ on CloseResource - ID: 2920057.

Thanks Nicolas !

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/branches/pmd/4.2.x@7049 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Romain Pelisse
2009-12-28 15:00:35 +00:00
parent c831d82bf0
commit 7a083a30e9
4 changed files with 52 additions and 3 deletions

View File

@ -1,5 +1,5 @@
???? - 4.2.6:
Fixed bug 2920057 - False + : CloseRessource whith an external getter
Fixed bug 1808110 - Fixed performance issue on PreserveStackTrace
Fixed bug 2832322 - cpd.xml file tag path attribute should be entity-encoded
Fixed bug 2590258 - NPE with nicerhtml output

View File

@ -179,5 +179,42 @@ public class Foo {
}
]]></code>
</test-code>
<test-code reinitializeRule="true">
<description><![CDATA[
invoke an external method that close the resource
bug 2920057
]]></description>
<rule-property name="closeTargets">fermerStatement,fermerStatement,fermerResultSet,fermerConnexion
</rule-property>
<rule-property name="types">PreparedStatement,Statement,ResultSet,Connection</rule-property>
<expected-problems>0</expected-problems>
<code><![CDATA[
import java.sql.*;
</test-data>
public class StructureFactory {
public void rechercherListe() {
Connection _connexion = null;
ArrayList <Structure> _listeStructure = new ArrayList<Structure>();
ResultSet _rs = null;
String _sql = "";
PreparedStatement _st = null;
Structure _structure = null;
try
{
//
}
finally
{
getFournisseurInstance().fermerConnexion(_connexion);
getFournisseurInstance().fermerResultSet(_rs);
getFournisseurInstance().fermerStatement(_st);
}
}
}
]]></code>
</test-code>
</test-data>

View File

@ -11,6 +11,7 @@ import net.sourceforge.pmd.ast.ASTCompilationUnit;
import net.sourceforge.pmd.ast.ASTLocalVariableDeclaration;
import net.sourceforge.pmd.ast.ASTMethodDeclaration;
import net.sourceforge.pmd.ast.ASTName;
import net.sourceforge.pmd.ast.ASTPrimarySuffix;
import net.sourceforge.pmd.ast.ASTReferenceType;
import net.sourceforge.pmd.ast.ASTTryStatement;
import net.sourceforge.pmd.ast.ASTType;
@ -130,6 +131,16 @@ public class CloseResource extends AbstractRule {
closed = true;
}
}
// look for primary suffix that could also contain close Targets elements.
List<ASTPrimarySuffix> suffixes = new ArrayList<ASTPrimarySuffix>();
f.findChildrenOfType(ASTPrimarySuffix.class, suffixes, true);
for (ASTPrimarySuffix oSuffix : suffixes) {
String suffix = oSuffix.getImage();
if (closeTargets.contains(suffix)) {
closed = true;
}
}
}
}

View File

@ -57,7 +57,8 @@
</subsection>
<subsection name="Contributors">
<ul>
<li>Sergey Pariev - Fixed an ugly ArrayIndexOutOfBoundsException in CPD for Ruby</li>
<li>Nicolas Dordet - Fixed an issue on CloseResource</li>
<li>Sergey Pariev - Fixed an ugly ArrayIndexOutOfBoundsException in CPD for Ruby</li>
<li>Chris Heister - Reported and noted proper fix for bug in IDEAJ renderer operations</li>
<li>Ralf Wagner - Reported bug in UselessOperationOnImmutable, reported and noted proper fix for broken XSLT</li>
<li>Caroline Rioux - Reported bug in ImmutableField</li>