Menu

#1375 CloseResource not detected properly

PMD-5.3.3
closed
None
PMD
3-Major
Bug
5.3.2
2015-06-20
2015-06-17
Rei Angelus
No

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

Related

Issues: #1372
Issues: #1387

Discussion

  • Andreas Dangel

    Andreas Dangel - 2015-06-20
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -1,8 +1,10 @@
     When the resource is initialized to NULL, the not closed resource seems to be not detect properly.
    
     For example :
    
    -   This is detected :
    
    +This is detected :
    +
    +~~~~~
     :::java
     public class Foo {
      void bar() {
    @@ -18,8 +20,11 @@
       } 
      }
     }
    +~~~~~
    
    
    -   But with NULL initialization, there is none detection:
    +But with NULL initialization, there is none detection:
    +
    +~~~~~
     :::java
     public class Foo {
      void bar() {
    @@ -35,6 +40,6 @@
       } 
      }
     }
    -
    +~~~~~
    
     Thanks
    
     
  • Andreas Dangel

    Andreas Dangel - 2015-06-20
    • status: open --> closed
    • assigned_to: Andreas Dangel
    • Milestone: New Tickets --> PMD-5.3.3
     

Log in to post a comment.

MongoDB Logo MongoDB