Uploaded image for project: 'AMQ Broker'
  1. AMQ Broker
  2. ENTMQBR-3817

[LTS] The createSession() method throws java.lang.NullPointerException

XMLWordPrintable

    • +
    • Hide
      Previously, if you used `javax.jms.Connection.createSession()` to create a session on a connection, you could see a null pointer exception. Specifically, this exception could occur if multiple threads were using the connection, and one thread closed the connection while the `createSessionInternal` method concurrently tried to create the session on a separate thread. This issue is resolved. Now, there are concurrency protections that prevent this type of exception from occurring.
      Show
      Previously, if you used `javax.jms.Connection.createSession()` to create a session on a connection, you could see a null pointer exception. Specifically, this exception could occur if multiple threads were using the connection, and one thread closed the connection while the `createSessionInternal` method concurrently tried to create the session on a separate thread. This issue is resolved. Now, there are concurrency protections that prevent this type of exception from occurring.
    • Documented as Resolved Issue
    • Verified in a release

      When calling a createSession on connection a java.lang.NullPointerException is thrown

      java.lang.NullPointerException
      	at org.apache.activemq.artemis.jms.client.ActiveMQConnection.createSessionInternal(ActiveMQConnection.java:619)
      	at org.apache.activemq.artemis.jms.client.ActiveMQConnection.createQueueSession(ActiveMQConnection.java:435)
      

      Looking at the code the same issue exist in AMQ 7.6 GA with later version or Artemis. The NPE is caused by ClientSessionFactory.Impl.createSessionInternal() method returning null if a connection is already closed. This condition may be triggered if multiple threads are trying to use a connection. If one thread closes a connection while another is trying to create a session the NPE may be triggered.

      I think it would be wise to check for null in

      ActiveMQConnection.createSessionInternal()

      before calling

      session.addFailureListener(listener);

      and throw an exception if it is.

              rhn-support-jbertram Justin Bertram
              rhn-support-jsherman Jason Sherman
              Tiago Bueno Tiago Bueno
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Created:
                Updated:
                Resolved: