Uploaded image for project: 'ActiveMQ Classic'
  1. ActiveMQ Classic
  2. AMQ-5959

NullPointerException in finally blocks

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 5.8.0, 5.12.0
    • 5.12.1, 5.11.3, 5.13.0
    • Broker

    Description

      Try blocks including a finally block that references a potential null object generating a NullPointerException.

      In The DestinationView.sendTextMessage(java.util.Map, ...) method for example (http://grepcode.com/file/repo1.maven.org/maven2/org.apache.activemq/activemq-broker/5.11.1/org/apache/activemq/broker/jmx/DestinationView.java#DestinationView.sendTextMessage%28java.util.Map%2Cjava.lang.String%2Cjava.lang.String%2Cjava.lang.String%29), I noticed code like the following:
      Connection connection = null;
      try

      { connection = cf.createConnection(userName, password); ... return msg.getJMSMessageID(); }

      finally

      { connection.close(); }

      There is no catch block and since an exception in the createConnection method could be thrown, connection would be null in the finally block, causing a NPE and masking the real exception.

      There may be other forms of this bad style which a code style checker should be able to locate for you.

      Attachments

        Activity

          People

            Unassigned Unassigned
            wjmcdonald William McDonald
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: