Uploaded image for project: 'JBoss Marshalling'
  1. JBoss Marshalling
  2. JBMAR-146

Serial impl: NullPointerException in org.jboss.marshalling.serial.PlainDescriptor when unmarshalling, in Java 6, object marshalled with Java 7

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • None
    • 1.3.17.GA
    • Serial
    • None
    • Compatibility/Configuration

      When I marshal a java.util.Locale object in Java 7 and then try to unmarshal it in Java 6 using the "serial" implementation, I get the following exception:

      Exception in thread "main" java.lang.NullPointerException
      	at org.jboss.marshalling.serial.PlainDescriptor.defaultReadFields(PlainDescriptor.java:151)
      	at org.jboss.marshalling.serial.PlainDescriptor.readSerial(PlainDescriptor.java:73)
      	at org.jboss.marshalling.serial.SerialUnmarshaller.doReadSerialObject(SerialUnmarshaller.java:348)
      	at org.jboss.marshalling.serial.SerialUnmarshaller.doReadObject(SerialUnmarshaller.java:288)
      	at org.jboss.marshalling.serial.SerialUnmarshaller.doReadObject(SerialUnmarshaller.java:78)
      	at org.jboss.marshalling.AbstractObjectInput.readObject(AbstractObjectInput.java:37)
      	at JBossUnmarshaller.main(JBossUnmarshaller.java:19)
      

      Note that the java.util.Locale class changed between Java 6 and Java 7 (a couple of fields were added), but its serialization API per the Java Serialization spec has not.

      This particular issue could be fixed by adding a null check to PlainDescriptor, but there's an underlying question: is the "serial" implementation meant to be compatible across Java versions?

      Below are the tests I used:

      JBossMarshaller.java
      import java.io.FileOutputStream;
      import java.io.IOException;
      import java.util.Locale;
      
      import org.jboss.marshalling.Marshaller;
      import org.jboss.marshalling.MarshallerFactory;
      import org.jboss.marshalling.Marshalling;
      import org.jboss.marshalling.MarshallingConfiguration;
      import org.jboss.marshalling.OutputStreamByteOutput;
      
      public class JBossMarshaller {
      
          public static void main(String[] args) throws IOException {
              FileOutputStream stream = new FileOutputStream("./testjboss-locale-1.7");
              MarshallerFactory factory = Marshalling.getProvidedMarshallerFactory("serial");
              MarshallingConfiguration config = new MarshallingConfiguration();
              
              Marshaller marshaller = factory.createMarshaller(config);
              
              marshaller.start(new OutputStreamByteOutput(stream));
              marshaller.writeObject(Locale.CANADA);
              marshaller.flush();
              marshaller.finish();
              stream.close();
          }
      
      }
      
      JBossUnmarshaller.java
      import java.io.FileInputStream;
      import java.io.IOException;
      
      import org.jboss.marshalling.InputStreamByteInput;
      import org.jboss.marshalling.MarshallerFactory;
      import org.jboss.marshalling.Marshalling;
      import org.jboss.marshalling.MarshallingConfiguration;
      import org.jboss.marshalling.Unmarshaller;
      
      public class JBossUnmarshaller {
          public static void main(String[] args) throws IOException, ClassNotFoundException {
              FileInputStream stream = new FileInputStream("./testjboss-locale-1.7");
              
              MarshallerFactory factory = Marshalling.getProvidedMarshallerFactory("serial");
              MarshallingConfiguration config = new MarshallingConfiguration();
              
              Unmarshaller unmarshaller = factory.createUnmarshaller(config);
              unmarshaller.start(new InputStreamByteInput(stream));
              Object obj = unmarshaller.readObject();
              unmarshaller.finish();
              
              System.out.println(obj);
              stream.close();
          }
      }
      
      

              Unassigned Unassigned
              atuladhar Amrit Tuladhar (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated: