Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6267224

Migration, interoperation failures for serialized javax.xml.namespace.QName inst. betw EE 1.4,SE 5.0

XMLWordPrintable

    • b01
    • other, x86
    • solaris_7, windows_2003

      DESCRIPTION:
      ===========
      Under jre5.0, an attempt to de-serialize an instance of the class javax.xml.namespace.QName, results in jvm throwing a java.io.InvalidClassException exception.

      ROOT CAUSE:
      ==========
      This issue is a result of the migration of javax.xml.namespace.QName
      from J2EE1.4 to J2SE5.0; the exception is thrown as a result of a mismatch between the suid reported in the ojbect file ('qnameser.obj') and the suid hard-coded into QName. Namely, in J2SE 5.0, the serialVersionUID of javax.xml.namespace.QName is declared:

          private static final long serialVersionUID = 4418622981026545151L;

      but in J2EE 1.4 this value is different.

      JDK VERSION INFORMATION:
      =======================
      java version "1.5.0_03"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_03-b07)
      Java HotSpot(TM) Server VM (build 1.5.0_03-b07, mixed mode)

      INSTRUCTIONS TO RECREATE ISSUE:
      ==============================
      The attached testcase and object file demonstrate the above issue. Run the test case by typing the following at the command line:
      $java QNameSerialTest d qnameser.obj

      NOTE: The file qnameser.obj was created using J2EE 1.4 and is available in the 'attachments' section.

      EXCEPTION DETAILS:
      =================
      When trying to run the test case (QNameSerialTest.java) - the following exception occurs:

      Failure during deserialization.
      java.io.InvalidClassException: javax.xml.namespace.QName; local class incompatible: stream classdesc serialVersionUID = -9120448754896609940, local class serialVersionUID = 4418622981026545151
              at java.io.ObjectStreamClass.initNonProxy(ObjectStreamClass.java:519)
              at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1546)
              at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1460)
              at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1693)
              at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1299)
              at java.io.ObjectInputStream.readObject(ObjectInputStream.java:339)
              at QNameSerialTest.main(QNameSerialTest.java:37)


      TESTCASE:
      ========

      import javax.xml.namespace.QName;
      import java.io.IOException;
      import java.io.ObjectInputStream;
      import java.io.ObjectOutputStream;
      import java.io.FileInputStream;
      import java.io.FileOutputStream;

      //Tests object serialization and deserialization of javax.xml.namepace.QName.

      public class QNameSerialTest {
          public final static String TEST_QNAME = "{http://www.example.com}test";
          
          public static void main (String [] args) {
              if (args.length < 2) {
                  printUsage();
                  System.exit(1);
              }
              if ("s".equals(args[0])) {
                  try {
                      ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(args[1]));
                      QName qname = QName.valueOf(TEST_QNAME);
                      oos.writeObject(qname);
                      oos.flush();
                      oos.close();
                      System.out.println("QName has been serialized to file: " + args[1]);
                  }
                  catch (IOException exc) {
                      System.err.println("Failure during serialization.");
                      exc.printStackTrace();
                  }
              }
              else if ("d".equals(args[0])) {
                  try {
                      ObjectInputStream ois = new ObjectInputStream(new FileInputStream(args[1]));
                      QName qname = (QName) ois.readObject();
                      ois.close();
                      System.out.println("Deserialization successful.");
                      System.out.println("QName value: " + qname.toString());
                  }
                  catch (ClassNotFoundException exc) {
                      System.err.println("Failure during deserialization.");
                      exc.printStackTrace();
                  }
                  catch (IOException exc) {
                      System.err.println("Failure during deserialization.");
                      exc.printStackTrace();
                  }
              }
              else {
                  printUsage();
                  System.exit(1);
              }
          }
          
          public static void printUsage() {
              System.err.println("Usage: java QNameSerialTest [s|d] file");
              System.err.println("s - serialize");
              System.err.println("d - deserialize");
          }
      }
      ###@###.### 2005-05-09 13:40:48 GMT
      ###@###.### 2005-05-23 23:46:55 GMT
      ###@###.### 2005-05-24 00:33:42 GMT

            tmoscovisunw Tal Moscovitz (Inactive)
            elarsen Erik Larsen (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: