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

Incorrect serialization of java.lang.ClassNotFoundException under jdk1.4

XMLWordPrintable

    • sparc
    • solaris_2.6



      Name: ooR10001 Date: 11/17/2000


      Serialization of java.lang.ClassNotFoundException class in jdk1.4 is incorrect.
      The following test is showing this bug:
      ----------------------------------------
      public class test {

        public static void main(String[] args) {
            ClassNotFoundException m = new ClassNotFoundException();
            try {
                java.io.FileOutputStream fos =
                    new java.io.FileOutputStream("test.ser");
                java.io.ObjectOutputStream oos =
                    new java.io.ObjectOutputStream(fos);
                oos.writeObject(m);
                oos.close();
                java.io.FileInputStream fis =
                    new java.io.FileInputStream("test.ser");
                java.io.ObjectInputStream ois =
                    new java.io.ObjectInputStream(fis);
                Object o = ois.readObject();
                ois.close();
            } catch (java.io.IOException e) {
                System.out.println("Exception thrown: " + e);
            } catch (ClassNotFoundException e) {
                System.out.println("Exception thrown: " + e);
            }
        }
      }
      ----------------------------------------

      Output:
      ---------------------------
      Exception in thread "main" java.lang.IllegalStateException: Can't overwrite cause
              at java.lang.Throwable.initCause(Throwable.java:305)
              at java.lang.ClassNotFoundException.readObject(ClassNotFoundException.java:115)
              at java.lang.reflect.Method.invoke(Native Method)
              at java.io.ObjectInputStream.invokeObjectReader(ObjectInputStream.java:2213)
              at java.io.ObjectInputStream.inputObject(ObjectInputStream.java:1410)
              at java.io.ObjectInputStream.readObject(ObjectInputStream.java:386)
              at java.io.ObjectInputStream.readObject(ObjectInputStream.java:236)
              at test.main(test.java:16)
      ---------------------------

      This needs to be fixed.

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

            jjb Josh Bloch
            oovsunw Oov Oov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: