0

I have used FindBugs tool in one of my java file and got below mentioned error message from tool.

I really found this mentioned issue while running my application. I have posted this on Getting TDS driver - java.lang.NullPointerException. this exception is not consistent .

I am not able to figure it out why this is coming.

1.)Method com.vtech.tdpms.dao.ClientAuthenticationDAO.authenticateClient(InputBean) may fail to clean up java.sql.ResultSet
Obligation to clean up resource created at ClientAuthenticationDAO.java:[line 44] is not discharged

Reference type java.sql.ResultSet
1 instance type of obligation remaining
Path continues at ClientAuthenticationDAO.java:[line 45]
Path continues at ClientAuthenticationDAO.java:[line 46]
Path continues at ClientAuthenticationDAO.java:[line 61]
Remaining obligations: {Statement x 1, ResultSet x 1}

2.)Method com.vtech.tdpms.dao.ClientAuthenticationDAO.authenticateClient(InputBean) may fail to clean up java.sql.Statement
Obligation to clean up resource created at ClientAuthenticationDAO.java:[line 38] is not discharged
Reference type java.sql.Statement
1 instance type of obligation remaining
Path continues at ClientAuthenticationDAO.java:[line 39]
Path continues at ClientAuthenticationDAO.java:[line 40]
Path continues at ClientAuthenticationDAO.java:[line 41]
Path continues at ClientAuthenticationDAO.java:[line 42]
Path continues at ClientAuthenticationDAO.java:[line 43]
Path continues at ClientAuthenticationDAO.java:[line 44]
Path continues at ClientAuthenticationDAO.java:[line 45]
Path continues at ClientAuthenticationDAO.java:[line 46]
Path continues at ClientAuthenticationDAO.java:[line 61]
Remaining obligations: {Statement x 1, ResultSet x 1}

Java code -

 public class ClientAuthenticationDAO extends DAOUtil {       
 private static LogManager LOG = new LogManager(ClientAuthenticationDAO.class);

 public boolean authenticateClient(InputBean objInputBean) throws SQLException {  // line 30
        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        boolean isAuthenticationSuccess = false;

        try {
            conn = getConnection();
            ps = conn.prepareStatement(ClientAuthenticationQueryUtil.AUTHENTICATE_CLIENT);    // line 38
            ps.setString(1, objInputBean.getUsername());                 // line 39
            ps.setString(2, objInputBean.getPassword());                 // line 40
            ps.setString(3, objInputBean.getCompanyCode());              // line 41
            rs = ps.executeQuery();                                      // line 42

            while(rs.next())  {                                        // line 44
                if(GenTools.isEmpty(objInputBean.getClientId())){         // line 45
                    objInputBean.setClientId(rs.getString("login_xid"));  // line 46
                }                   
                objInputBean.setAdminId(rs.getInt("admin_id"));
                objInputBean.setLoginUserPID(rs.getInt("login_user_pid"));
                objInputBean.setUserType(rs.getString("user_type"));
                isAuthenticationSuccess = true;
            }

        } catch (SQLException sqlExp) {
            sqlExp.printStackTrace();
            LOG.fatal(sqlExp);
            throw sqlExp;
        } finally {
            DataBaseUtil.close(conn, ps, rs);
        }           

        return isAuthenticationSuccess;
    }

}

Community
  • 1
  • 1
Santosh
  • 782
  • 4
  • 15
  • 38
  • what happens if you manually close the ps and rs in your finally block? i.e. by calling `ps.close()` and `rs.close()` respectively. – Emil L Feb 25 '12 at 06:32
  • Why is this question tagged as `NullPointerException`? That tag seems to refer to another question. – tom Feb 25 '12 at 07:56
  • while executing this code, getting NullPointerException - please refer - http://stackoverflow.com/q/9411706/147075 – Santosh Feb 25 '12 at 08:01
  • I know you are getting an NPE but this is a FindBugs question. – tom Feb 25 '12 at 08:14

1 Answers1

1

We have the same messages in Sonar. This comes from the fact that findbugs does not know DataBaseUtil.close(conn, ps, rs); actually closes your resources. Findbugs searches for the actual call for the resource in the same method.

tom
  • 2,735
  • 21
  • 35