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

sun.java2d.T1FontObject is not serializable which breaks java.awt.Font

XMLWordPrintable

    • 2d
    • generic
    • solaris_2.5.1

      When I tried to serialize a class that has a serializable class in it (java.awt.Font) I get this exception:

      java.io.NotSerializableException: sun.java2d.T1FontObject
              at java.io.ObjectOutputStream.outputObject(ObjectOutputStream.java:704)
              at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:238)
              at java.io.ObjectOutputStream.outputClassFields(ObjectOutputStream.java:1250)
              at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:339)
              at java.awt.Font.writeObject(Font.java:527)
              at java.lang.reflect.Method.invoke(Native Method)
              at java.io.ObjectOutputStream.invokeObjectWriter(ObjectOutputStream.java:1269)
              at java.io.ObjectOutputStream.outputObject(ObjectOutputStream.java:747)
              at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:238)
              at java.io.ObjectOutputStream.outputClassFields(ObjectOutputStream.java:1250)
              at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:339)
              at java.io.ObjectOutputStream.outputObject(ObjectOutputStream.java:751)
              at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:238)
              at Test.main(Test.java:17)

      The underlying 2d java FontObject must not implements Serializable.

      import java.io.*;
      import java.awt.*;

      public class Test implements Serializable {
          Font font;

          Test() {
      font = new Font("Helvetica", Font.BOLD, 20);
          }

          public static void main(String args[]) {
      ByteArrayOutputStream bo = null;

      try {
      bo = new ByteArrayOutputStream();
      ObjectOutputStream so = new ObjectOutputStream(bo);
      so.writeObject(new Test());
      so.flush();
      } catch (Exception e) {
      e.printStackTrace();
      System.exit(1);
      }

      try {
      ByteArrayInputStream bi =
      new ByteArrayInputStream(bo.toByteArray());
      ObjectInputStream si = new ObjectInputStream(bi);
      si.readObject();
      } catch (Exception e) {
      e.printStackTrace();
      System.exit(1);
      }
          }
      }

            jkaulorcl Jeet Kaul (Inactive)
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: