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

Incompatible change in serial fields for java.awt.Font class

XMLWordPrintable

    • 2d
    • beta
    • sparc
    • solaris_2.6



      Name: ooR10001 Date: 11/16/2000


      Field 'fRequestedAttributes' change type in jdk build 1.4beta-B40 from 'Hashtable' to
      'HashMap'. There causes compatibility problem when attempt
      to deserialize object from jdk1.3 stream in jdk1.4beta-B40.
      The following test showing this bug:
      ------------------------------------------
      public class test {

        public static void main(String[] args) {
          if (args.length == 0) {
              java.awt.Font m = new java.awt.Font(null);
              try {
                  java.io.FileOutputStream fs =
                      new java.io.FileOutputStream("test.ser");
                  java.io.ObjectOutputStream oos =
                      new java.io.ObjectOutputStream(fs);
                  oos.writeObject(m);
                  oos.close();
      } catch (java.io.IOException e) {
                  System.out.println("FAILED:" + e);
      }
          } else {
              Object m = null;
              try {
                  java.io.FileInputStream fs =
                      new java.io.FileInputStream("test.ser");
                  java.io.ObjectInputStream ois =
                      new java.io.ObjectInputStream(fs);
                  m = ois.readObject();
                  ois.close();
      } catch (java.io.IOException e) {
                  System.out.println("FAILED:" + e);
      } catch (ClassNotFoundException e) {
                  System.out.println("FAILED:" + e);
      }
              if (m instanceof java.awt.Font) {
                  System.out.println("OKAY");
      } else {
                  System.out.println("FAILED");
      }
          }
        }

      }
      ------------------------------------------

      Execiting following commands to create stream with java.awt.Font object under jdk1.3:
      %javac test.java
      %java test
      ----------------------
      Executing following command to deserialize object in jdk1.4beta-B40:
      %javac test.java
      %java test tt
      ----------------------
      Result of execution:
      ----------------------
      Exception in thread "main" java.lang.ClassCastException: Assigning instance of class
      java.util.Hashtable to field java.awt.Font#fRequestedAttributes
              at java.io.ObjectInputStream.inputClassFields(ObjectInputStream.java:2270)
              at java.io.ObjectInputStream.defaultReadObject(ObjectInputStream.java:519)
              at java.awt.Font.readObject(Font.java:953)
              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:23)
      ----------------------

      This needs to be fixed.

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

            dougfelt Doug Felt (Inactive)
            oovsunw Oov Oov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: