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

(reflect) java.lang.reflect classes should be serializable

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.3.0
    • core-libs



      Name: rmT116609 Date: 10/02/2000


      java version "1.3.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-beta_refresh)
      Java HotSpot(TM) Client VM (build 1.3.0-beta_refresh, mixed mode)


      I use the Constructor class very heavily to create objects and want to be
      able to serialize the creator.

      Complete Java source code that demonstrates the problem.

      import java.lang.reflect.*;
      import java.io.*;

      public class SerBug implements Serializable {
          
          Constructor[] c = Object.class.getConstructors();

          public static void main (String args[]) throws Exception {
      ObjectOutputStream out = new ObjectOutputStream(new
      FileOutputStream("bug.out"));
      out.writeObject(new SerBug());
          }
      }


      > - The exact text of any error message(s) that appeared.

      Exception in thread "main" java.io.NotSerializableException:
      java.lang.reflect.Constructor
              at
      java.io.ObjectOutputStream.outputObject(ObjectOutputStream.java:1148)
              at
      java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:366)
              at
      java.io.ObjectOutputStream.outputArray(ObjectOutputStream.java:1098)
              at
      java.io.ObjectOutputStream.checkSubstitutableSpecialClasses(ObjectOutputStream.java:456)
              at
      java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:361)
              at
      java.io.ObjectOutputStream.outputClassFields(ObjectOutputStream.java:1841)
              at
      java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:480)
              at
      java.io.ObjectOutputStream.outputObject(ObjectOutputStream.java:1214)
              at
      java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:366)
              at SerBug.main(SerBug.java:10)

      > - Any trace information.

      It is obviously that the class does not implement the Serializable
      interface (which will change soon, I hope).

      The problem is not alone with the Constuctor. It is common to all
      classes in the java.lang.reflect package and is IMHO simply unnecessary.
      (Review ID: 109058)
      ======================================================================

            iris Iris Clark
            rmandalasunw Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: