Affects PMD Version: PMD ??? (1.2.2 is an invalid version...)
Rule: CloseResourceRule
Description:
The CloseResourceRule does not identify in case the resource variable got re assigned by developer
Code Sample demonstrating the issue:
public class Bar {
public void withSQL() {
Connection c = pool.getConnection();
try {
// do stuff
// oops, should not have assgined the connection again to the variable
c = pool.getConnection();
} catch (SQLException ex) {
// handle exception
} finally {
// oops, one connection leak'!
c.close();
}
}
}
Expected outcome:
- It is expected that PMD reports a violation of resource re assignment. The other rules DataflowAnomalyAnalysisRule and java/bestpractices/UnusedAssignment is not effective also to detect this .
- Is PMD missing to report a violation, where there should be one? -> false-negative
Running PMD through: [CLI | Ant | Maven | Gradle | Designer | Other]
Affects PMD Version: PMD ??? (1.2.2 is an invalid version...)
Rule: CloseResourceRule
Description:
The CloseResourceRule does not identify in case the resource variable got re assigned by developer
Code Sample demonstrating the issue:
Expected outcome:
Running PMD through: [CLI | Ant | Maven | Gradle | Designer | Other]