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

ActiveMqSession should throw JMSException instead of IllegalStateException if connection is closed

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Critical
    • Resolution: Won't Fix
    • 5.3.2
    • 5.4.0
    • None
    • None
    • Spring 2.5.6

    Description

      ActiveMqSession throws IllegalStateException if connection is closed. The ActiveMqSession.checkClosed() will throw the exception if the connection is lost. This is really an internal error which according to the javax.jms.Session.commit javadoc should result in a JMSException.

      The distinction between the two exceptions becomes important when using Spring and ActiveMq. When doing JMS inside a codeblock that is managed by a HibernateTransactionManager (or any other non-JmsTransactionManager/non-JtaTransactionManager) TransactionSynchronizationUtils will try to commit the jms session after the HibernateTransactionManager has committed. This is done by calling the JmsResourceHolder.commitAll() from TransactionSynchronizationManager.invokeAfterCommit(). JmsResourceHolder.commitAll() will silently ignore IllegalStateExceptions as these are only supposed to happen in the case of a JTA transaction.

      If ActiveMqSession.commit -> ActiveMqSession.checkClosed() were to throw a JMSException it would propagate out of the TransactionSynchronizationUtils and at least the application would be made aware that the JMSSession was not committed.

      Below is the description of IllegalStateException from the JMS Specification:
      IllegalStateException: This exception is thrown when a method is invoked a
      an illegal or inappropriate time or if the provider is not in an appropriate
      state for the requested operation. For example, this exception must be
      thrown if Session.commit() is called on a non-transacted session. This
      exception is also must be called when domain inappropriate method is
      called, such as calling TopicSession.CreateQueueBrowser().

      While it does not specifically state that a closed connection should NOT throw an IllegalStateException, it would seem that throwing a JMSException is a better choice. Especially when IllegalStateException causes problems when using Spring.

      Attachments

        Activity

          People

            rajdavies Robert Davies
            magott Morten Andersen-Gott
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: