History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: IDEADEV-14031
Type: Bug Bug
Status: Open Open
Priority: Major Major
Assignee: Maxim Shafirov
Reporter: Serge Baranov
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
IDEA: Development

Wrong warning: method invocation may produce a NullPointerException

Created: 16 Feb 06 20:43   Updated: 06 Nov 08 23:24
Component/s: Code Analysis. Inspection
Fix Version/s: Undefined

Original Estimate: Unknown Remaining Estimate: Unknown Time Spent: Unknown

Build: 4,155


 Description  « Hide
Yan Pujante reports:
/**
 * $Id$ */
package test.misc;

import java.sql.Connection;
import java.sql.SQLException;

/**
 * @author Yan Pujante
 * @version $Revision$
 */
public class TestIDEAWarn
{
  private Connection _connection;

  /**
   * Constructor
   */
  public TestIDEAWarn(Connection connection)
  {
    _connection = connection;
  }

  public void warn() throws SQLException
  {
    try
    {
      try
      {
        System.out.println("in try");
      }
      finally
      {
        if(_connection != null)
        {
          try
          {
            _connection.commit();
          }
          finally
          {
            _connection.close();
            _connection = null;
          }

        }
      }
    }
    catch(SQLException e)
    {
      throw new RuntimeException(e);
    }
  }
}

IDEA warns me that _connection.close() may produce a NullPointerException. If I remove the line _connection = null, the
warning goes away.. note that the assignment is AFTER using the object!

Note that if you comment out the block catch(SQLException) { } then
the warning goes away which is weird.



 All   Comments   Work Log   Change History      Sort Order:
There are no comments yet on this issue.