When the resource is initialized to NULL, the not closed resource seems to be not detect properly.
For example :
This is detected :
:::java
public class Foo {
void bar() {
ResultSet rs;
Statement stmt = getConnection().createStatement();
try {
rs = stmt.getResultSet();
rs.getString(0);
rs.close();
} catch (Exception e) {
} finally {
stmt.close();
}
}
}
But with NULL initialization, there is none detection:
:::java
public class Foo {
void bar() {
ResultSet rs = null;
Statement stmt = getConnection().createStatement();
try {
rs = stmt.getResultSet();
rs.getString(0);
rs.close();
} catch (Exception e) {
} finally {
stmt.close();
}
}
}
Thanks
Diff:
Thanks for the bug report. This will be fixed with pmd 5.3.3.
Commit: https://github.com/pmd/pmd/commit/1b35a59997a5456ec68cf0d3d829f5ac1dc12f08