Session replication is failing with the exception java.io.NotSerializableException in JBoss EAP

Solution Verified - Updated -

Environment

  • Red Hat JBoss Enterprise Application Platform (EAP)
    • 6.x
    • 7.x
    • 8.x

Issue

  • Session replication is failing with the exception java.io.NotSerializableException in JBoss EAP
  • In JBoss EAP, serialization fails with the following ERROR:

    ERROR [org.infinispan.interceptors.InvocationContextInterceptor] (ajp-/10.1.2.3:8009-2) ISPN000136: Execution error: org.infinispan.CacheException: java.lang.RuntimeException: Failure to marshal argument(s)
    ...
    Caused by: org.infinispan.marshall.NotSerializableException: this.is.my.object
    Caused by: an exception which occurred:
    in field myField
    in object java.util.HashMap@3ceddee4
    in object org.jboss.as.clustering.SimpleMarshalledValue@3ceddee4
    in object org.infinispan.atomic.PutOperation@20530a83
    in object java.util.LinkedList@f2784c57
    in object org.infinispan.atomic.AtomicHashMapDelta@13452861
    in object org.infinispan.commands.write.PutKeyValueCommand@e593a539
    in object org.infinispan.commands.tx.PrepareCommand@7acfe1a3
    

Resolution

  • Ensure that all classes that are put into the HTTP session implement java.io.Serializable interface. Note that all members of a Serializable class must also be java.io.Serializable or be marked as transient to be excluded from serialization.

  • If an object in the session has a log4j Logger in it, but the Log4J Loggers are not serializable you can do one of two things:

    • Mark the logger as transient (if you are using a separate logger for each instance)
    • Mark the logger as static
  • If it is not possible to modify the class to implement java.io.Serializable interface (or be marked as transient to be excluded from serialization), disable clustering to avoid session replication.

Root Cause

The java.io.NotSerializableException will occur whenever a non-serializable class resides in the session and the session is replicated.

JBoss EAP has no way to serialize a class that does not implement the Serializable interface. It will, therefore, throw an exception. Note that clustering will not work properly if this issue is not resolved, this is because the marshalling process, i.e passing converted information from POJO to the wire is a vital process on the cluster. The marshalling process is based on the JBoss Marshalling Framework, instead of Java framework for improving the performance.

The purpose of clustering is to achieve high availability, which is achieved through replication. The NotSerializableException error hinders replication and interferes in this process.

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments