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

Bug in reflection/serialization combination with primitive types

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.2.2
    • core-libs



      Name: rlT66838 Date: 08/23/99


      When a primitive type's class is serialized, this is not
      received properly upon reading (only tested this to/from file
      serialization).

      Steps:
      serialization:
      1. Class c = Integer.TYPE // get the class of the primitive
      2. objectOutputStream.writeObject (c); // serizalize

      deserialization:
      1. Class c = (Class) objectInputStream.readObject ();
      output:
      java.lang.ClassNotFoundException: int
              at java.io.ObjectInputStream.readObject(ObjectInputStream.java:347)
              at java.io.ObjectInputStream.readObject(ObjectInputStream.java:232)
              at sr.firm.welch.brian.Tester.main(Tester.java:23)

      Code that demonstrates this:
      > Begin code example
      package sr.firm.welch.brian;

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

      public class Tester
      {
         public static void main (String args[])
         {
            try
            {
               // serialize
               FileOutputStream fos = new FileOutputStream ("intClass.ser");
               ObjectOutputStream oos = new ObjectOutputStream (fos);
               Class c = Integer.TYPE;
               oos.writeObject (c);
               oos.close ();
               fos.close ();

               // deserialize
               FileInputStream fis = new FileInputStream ("intClass.ser");
               ObjectInputStream ois = new ObjectInputStream (fis);
               c = (Class) ois.readObject (); // This is where the exception is thrown
               System.out.println ("This is never reached");
               ois.close ();
               fis.close ();
            }
            catch (Exception except)
            {
               except.printStackTrace ();
            }
         }
      }
      > End code example


      version info:
      java -version
      java version "1.2.1"
      Classic VM (build JDK-1.2.1-A, native threads)

      java -fullversion
      java full version "JDK-1.2.1-A"

      relevant configuration (though I do not believe this has impact
      on the bug):
      - Intel Pentium II 400
      - 128 MB RAM
      - OS=Windows NT 4.0 SP4
      (Review ID: 93724)
      ======================================================================

            nsanjeevsunw Naveen Sanjeeva (Inactive)
            rlewis Roger Lewis (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: