4 Replies Latest reply on Oct 23, 2001 11:43 AM by pazu

    Strange behavior with null pointers

    pazu

      Something strange is happening in my app: here is the piece of code:

      protected void closeStatement(PreparedStatement stmt) throws DAOSysException
      {
      try
      {
      if (stmt != null)
      stmt.close();
      }
      catch (SQLException se)
      {
      throw new DAOSysException("Erro ao fechar o statement:" + se);
      }
      catch (NullPointerException se)
      {
      System.out.println("NPE!!!");
      }
      }


      now you should be wondering: Why do I need to catch a NullPointerException if I'm already doing an if (stmt != null) ??? I'd be asking the same question. It seems that the statement is disappearing between the test and close(). Really strange...