UF.SQLCON

UF (Use Freed) issues are reported when there is an attempt to use resources after they were released. The UF.SQLCON warning indicates an attempt to use a JDBC connection 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);
         populate(strings, 0, 2, 4, 6, 8);
         return strings;
     }
 
     public void populate(List<String> data, int... keys) {
         try {
             PreparedStatement ps = conn.prepareStatement("SELECT * FROM Table where key=?");
             try {
                 for (int key : keys) {
                     ps.setInt(1, key);
                     final ResultSet resultSet = ps.executeQuery();
                     try {
                         populate(data, resultSet);
                     } finally {
                         resultSet.close();
                     }
                 }
             } catch (SQLException e) {
                 conn.close();
             }  finally {
                 ps.close();
             }
         } catch (SQLException e) {
             // do nothing
         }
     }
 
     public void populate(List<String> data, ResultSet rs) throws SQLException {
         while (rs.next()) {
             String s = rs.getString(1);
             data.add(s);
         }
     }

UF.SQLCON is reported for the snippet on line 29 since the method 'populate' called on line 28 is closing the JDBC connection 'conn' in case of any SQLException thrown. That means that the next call to 'populate' on line 29 might attempt to use the closed connection.