-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
1.2.0
-
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);
}
}
}
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);
}
}
}
- duplicates
-
JDK-4080653 AWT font class is no longer serializable
-
- Closed
-