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

Incorrect serialization of InvocationTargetException under jdk1.4

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      sparc
    • OS:
      solaris_2.6

      Description



      Name: ooR10001 Date: 11/17/2000


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

        public static void main(String[] args) {
            java.lang.reflect.InvocationTargetException m =
                    new java.lang.reflect.InvocationTargetException(null);
            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.reflect.InvocationTargetException.readObject(InvocationTargetException.java:90)
              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:17)
      ---------------------------

      This needs to be fixed.

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

        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: