#1372 False Negative for CloseResource rule.

already fixed with #1375
This commit is contained in:
Andreas Dangel
2015-06-20 18:38:09 +02:00
parent 1b35a59997
commit 2b92e22546
2 changed files with 34 additions and 0 deletions

View File

@@ -571,6 +571,39 @@ public class Foo {
stmt.close();
}
}
}
]]></code>
</test-code>
<test-code>
<description>#1372 False Negative for CloseResource rule.</description>
<expected-problems>1</expected-problems>
<expected-linenumbers>8</expected-linenumbers>
<rule-property name="types">Connection,Statement,ResultSet,PreparedStatement</rule-property>
<rule-property name="closeTargets">closeLocalResources,closeResultSet</rule-property>
<code><![CDATA[
public class CloseResourceTest {
public Object selectOne(final int val, final int val2) {
getCurrentSession().doWork(new Work() {
@Override
public void execute(Connection connection) throws SQLException {
PreparedStatement stmt = null;
ResultSet rs = null;
try {
stmt = createDefaultPreparedStatement(connection, CONSTANTS.QUERY_STRING);
stmt.setInt(1, vaL);
stmt.setInt(2, val2);
rs = stmt.executeQuery();
// do result set processing
} catch (SQLException se) {
// error
} finally {
closeLocalResources(stmt);
//closeResultSet(rs); // --- ERROR
}
}
});
}
}
]]></code>
</test-code>

View File

@@ -17,6 +17,7 @@
* [#1364](https://sourceforge.net/p/pmd/bugs/1364/): FieldDeclarationsShouldBeAtStartOfClass false positive using multiple annotations
* [#1365](https://sourceforge.net/p/pmd/bugs/1365/): Aggregated javadoc report is missing
* [#1366](https://sourceforge.net/p/pmd/bugs/1366/): UselessParentheses false positive on multiple equality operators
* [#1372](https://sourceforge.net/p/pmd/bugs/1372/): False Negative for CloseResource rule.
* [#1375](https://sourceforge.net/p/pmd/bugs/1375/): CloseResource not detected properly
**API Changes:**