UF.SQLOBJ

UF (Use Freed) issues are reported when there is an attempt to use resources after they were released. The UF.SQLOBJ warning indicates an attempt to use a JDBC object (such as a statement, prepared statement or result set) after it was closed.

Example 1

Copy
    public List<String> order() {
         final List<String> strings = new ArrayList<String>();
         populate(strings, 1, 3, 5, 7, 9);
         return strings;
     }
 
     public void populate(List<String> data, int... keys) {
         try {
             try {
                 ps = conn.prepareStatement("SELECT * FROM Table where key=?");
                 for (int key : keys) {
                     populate(data, key);
                 }
             } finally {
                 ps.close();
             }
         } catch (SQLException e) {
             // do nothing
         }
     }
 
     public void populate(List<String> data, int key) {
         try {
             ps.setInt(1, key);
             final ResultSet rs = ps.executeQuery();
             try {
                 while (rs.next()) {
                     String s = rs.getString(1);
                     data.add(s);
                 }
             } finally {
                 rs.close();
             }
         } catch (SQLException e) {
             try {
                 ps.close();
             } catch (SQLException e1) {
                 // do nothing
             }
         }
     }

UF.SQLOBJ is reported for the snippet on line 39: the method 'populate(List<String> data, int... keys)' is called on line 39 on every iteration of the cycle. This method is closing the prepared statement 'ps' in case of any SQLException thrown (see line 63). This might cause an attempt to use the closed prepared statemnt on the next iteration of the cycle.