forked from phoedos/pmd
Adding new test case to validate a new features in CloseResourceRule
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@5559 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -147,4 +147,37 @@ public class Foo {
|
|||||||
}
|
}
|
||||||
]]></code>
|
]]></code>
|
||||||
</test-code>
|
</test-code>
|
||||||
|
<test-code reinitializeRule="true">
|
||||||
|
<description><![CDATA[
|
||||||
|
New use case
|
||||||
|
]]></description>
|
||||||
|
<rule-property name="closeTargets">commit,close,close,close</rule-property>
|
||||||
|
<rule-property name="types">DAOTransaction,Connection,Statement,ResulSet</rule-property>
|
||||||
|
<expected-problems>2</expected-problems>
|
||||||
|
<code><![CDATA[
|
||||||
|
import java.sql.*;
|
||||||
|
public class Foo {
|
||||||
|
public void bar() throws SQLException
|
||||||
|
{
|
||||||
|
DAOTransaction = null;
|
||||||
|
Connection cnx = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
Statement stmt = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
rs.close(); // Correct
|
||||||
|
//stmt.close(); // Error !!! you have to close the Statement
|
||||||
|
cnx.commit(); // Error !!! You have to use close() before doing this !
|
||||||
|
DAOTransaction.commit(); // Correct
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]]></code>
|
||||||
|
</test-code>
|
||||||
|
|
||||||
</test-data>
|
</test-data>
|
Reference in New Issue
Block a user