JBoss Community

Modular Serialization

modified by Jason Greene in JBoss AS7 Development - View the full document

Understanding Class-loading Issues

When an object is serialized using Java serialization, the format consists of a "class reference" and the field data of every field in all inheriting classes. The class reference is simply a class name. The assumption is that the recieving party has a all of the sender's class definitions readily accessable to the thread's current context class loader. This means very different semantics than those commonly expected in a normal in-vm invocation accross class loader boundaries. In a modularized environment, it is not only common, but considered good practice to only share public API types and yet still pass internal implementation classes that back the API types across module boundaries. These "opaque" structures don't cause the VM a problem because the same phsysical, already constructed, object instance is being passed around.

 

However, with serialization there is no object instance. All fields of all types that make up an object need to be accessed to recreate the instance. Also since fields themesleves may be references to other custom types, it is quite common for a large graph referencing numerous types to be on the wire, and thus have a need for visibility.

Problem A - Subclass Visibility

In this example a common super class is shared between a sender and a receiver, but an extened subclass used by the sender's implementation is mistakenly not shared. This case works just fine wiht local IN-VM invocations, but will fail once serialization is involved.

http://community.jboss.org/servlet/JiveServlet/downloadImage/102-17244-4-17060/450-438/ModularSerializationExample.png

Problem B - Reference / Aggregation Visibility

In this example a common class is shared between a sender and a receiver, but it contains a field which references a sender class that is mistakenly not shared. This case works just fine with local IN-VM invocations, but will fail once serialization is involved.

http://community.jboss.org/servlet/JiveServlet/downloadImage/102-17244-4-17061/450-439/ModularSerializationProblemB.png

Comment by going to Community

Create a new document in JBoss AS7 Development at Community