Menu

#1259 CloseResource rule ignores conditionnals within finally blocks

PMD-5.2.1
closed
None
PMD
3-Major
Bug
5.1.3
2014-11-03
2014-09-08
No

With PMD 5.1.3, no warning is given when analysing this piece of code:

~~~~~~~~~
public class Bar {

public void foo() {
    Connection c = pool.getConnection();
    try {
        // do stuff
    } catch (SQLException ex) {
        // handle exception
    } finally {
        if(false) {
            c.close();
        }
    }
}

}
~~~~~~~~~~

The rule does not seem to take the "if" into account inside a finally block, and considers that c.close will be executed even if the code is dead. Whichever condition is set in the conditionnal (false, true, a variable, etc), PMD won't send a warning.

Discussion

  • Andreas Dangel

    Andreas Dangel - 2014-10-24
    • status: open --> in-progress
    • assigned_to: Andreas Dangel
    • Milestone: New Tickets --> PMD-next
     
  • Andreas Dangel

    Andreas Dangel - 2014-11-03
    • status: in-progress --> closed
     

Log in to post a comment.