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

AWT font class is no longer serializable

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P1 P1
    • 1.2.0
    • 1.2.0
    • client-libs
    • None
    • 2d
    • 1.2beta1
    • generic, sparc
    • solaris_2.5.1
    • Not verified


      It is no longer possible to serialize awt Font objects. This is because
      the Font class now has a FontObject field, and some FontObjects such as
      sun.java2d.T1FontObject aren't serializable.

      If you try and run the test program below you get:

      Font write failed: java.io.NotSerializableException: sun.java2d.T1FontObject
      java.io.NotSerializableException: sun.java2d.T1FontObject
              at java.io.ObjectOutputStream.outputObject(ObjectOutputStream.java:753)
              at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:232)
              at java.io.ObjectOutputStream.outputClassFields(ObjectOutputStream.java:1351)
              at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:383)
              at java.awt.Font.writeObject(Font.java:584)
              at java.lang.reflect.Method.invoke(Native Method)
              at java.io.ObjectOutputStream.invokeObjectWriter(ObjectOutputStream.java:1370)
              at java.io.ObjectOutputStream.outputObject(ObjectOutputStream.java:796)
              at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:232)
              at Test.main(Test.java:17)


      import java.awt.*;

      public class Test extends java.awt.Frame {

          public static void main(String argv[]) {
              Frame frame = new Test();

              frame.setBounds(200,200,200,200);
              frame.show();

              Font font = frame.getFont();

              try {
                  java.io.FileOutputStream fout = new java.io.FileOutputStream("foo.ser");
                  java.io.ObjectOutput s = new java.io.ObjectOutputStream(fout);
                  s.writeObject(font);
                  s.close();

                  System.exit(0);

              } catch (Exception ex) {
                  System.err.println("Font write failed: " + ex);
                  ex.printStackTrace();
              }
          }
      }


      KGH 9/21/97

            jkaulorcl Jeet Kaul (Inactive)
            ghamiltosunw Graham Hamilton (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: