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

java.lang.ExceptionInInitializerError is incorrectly deserialized

XMLWordPrintable

    • 1.2fcs
    • sparc
    • solaris_2.4, solaris_2.5
    • Verified



      Name: avC70361 Date: 05/14/98



        The java.lang.ExceptionInInitializerError is incorrectly deserialized in
      jdk1.2-beta4 when have been serialized in jdk1.1.6. The exception
      InvalidClassException is thrown

      Here is the test demonstarating the bug.
      --------------ExceptionInInitializerErrorTest.java--------
      import java.io.*;

      public class ExceptionInInitializerErrorTest {

        public static void main(String args[]) {

          ExceptionInInitializerError exception = new ExceptionInInitializerError(
            new Exception("")
          );

          if (args[0].equals("write")) {

            ObjectOutputStream stream = null;

            try {

              stream = new ObjectOutputStream(new FileOutputStream(args[1]));
              stream.writeObject(exception);
              stream.close();

            } catch(IOException e) {
              System.out.println("Couldn't write to " + args[1] + " : " + e);
              System.exit(1);
            }

            System.out.println(args[1] + " written successfully");

          } else if (args[0].equals("read")) {

            ObjectInputStream stream = null;

            try {

              stream = new ObjectInputStream(new FileInputStream(args[1]));
              exception = (ExceptionInInitializerError)stream.readObject();

            } catch(InvalidClassException e) {
              System.out.println("Failed:" + e);
              System.exit(1);
            } catch(Exception e) {
              System.out.println(
                "Failed: couldn't read from" + args[1] + " : " + e
              );
              System.exit(1);
            }

            System.out.println("Passed");

          }

          System.exit(0);

        }

      }
      -------------The test output-----------
      Under jdk1.1.6:
      <avv@stardust(pts/24).292> java -fullversion
      java full version "JDK1.1.6N"
      <avv@stardust(pts/24).293> java ExceptionInInitializerErrorTest write file.ser
      file.ser written successfully
      <avv@stardust(pts/24).294> java ExceptionInInitializerErrorTest read file.ser
      Passed

      Under jdk1.2beta4:
      <avv@stardust(pts/2).555> java -fullversion
      java full version "JDK-1.2beta4-E"
      <avv@stardust(pts/2).556> java ExceptionInInitializerErrorTest read file.ser
      Failed:java.io.InvalidClassException: java.lang.ExceptionInInitializerError; Local class not compatible: stream classdesc serialVersionUID=1521711792217232256 local class serialVersionUID=7892170544829138779

      ======================================================================

            apalanissunw Anand Palaniswamy (Inactive)
            ovlasov Oleksandr Vlasov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: