JMS: some objects are no longer serializable

JMS objects such as JMS Connections and JMS Sessions, which used to be serializable when using the IBM® MQ classes for JMS for IBM WebSphere® MQ 7.0.1, are no longer serializable when using IBM WebSphere MQ 7.1 or later.

When a Java application serializes an object, state information about that object is written to an output stream, such as a file. The contents of output stream can then be read at a later date, to reconstruct (or deserialize) the Java object so that it can be reused.

The following interfaces provided by the IBM MQ classes for JMS are implemented by objects that represent an active connection from an application to an IBM MQ queue manager:
  • JMSConnection
  • JMSQueueConnection
  • JMSTopicConnection
  • JMSSession
  • JMSQueueSession
  • JMSTopicSession

There is an IBM MQ connection handle (hconn) associated with every JMSConnection, JMSQueueConnection, JMSTopicConnection, JMSSession, JMSQueueSession and JMSTopicSession object that is created by an application.

Serializing one of these objects would result in state information about those objects being written to an output stream. This included information about the connection handle to IBM MQ that was associated with the object.

However, there was no guarantee that the connection handle would still be valid when the object was deserialized and resused, which could lead to unexpected behavior. To prevent applications running into these issues, the IBM MQ classes for JMS for Version 7.1 (and later) will throw a NotSerializableException if an application tries to:
  • Serialize a JMSConnection, JMSQueueConnection, JMSTopicConnection, JMSSession, JMSQueueSession or JMSTopicSession object using the method:
    
    writeObject(ObjectOutputStream)
    
  • Deserialize a JMSConnection, JMSQueueConnection, JMSTopicConnection, JMSSession, JMSQueueSession or JMSTopicSession object using the method:
    
    readObject(ObjectInputStream)