-
Bug
-
Resolution: Unresolved
-
P4
-
None
-
1.4.0
-
generic
-
generic
Name: dsR10078 Date: 06/01/2001
###@###.###
Class Cursor is declared to implement Serializable, however custom Cursors
cannot be serialized.
Here is the test case that reproduces the problem:
------------------------------------------------------------------------
import java.awt.*;
import java.io.*;
public class Test {
public static void main(String[] args) {
final Toolkit tk = Toolkit.getDefaultToolkit();
final Image image = tk.createImage("middle.gif");
final Point p = new Point();
final Cursor cursor = tk.createCustomCursor(image, p, "");
if (cursor instanceof Serializable) {
try {
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(cursor);
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
------------------------------------------------------------------------
I used middle.gif available from
http://www.java.sun.com/docs/books/tutorial/uiswing/components/example-swing/images/middle.gif
Here is the output i get:
<das@horror(pts/7).286> /set/jdk-builds/JDK1.4.0beta-b65/solaris/bin/java -ver>
java version "1.4.0-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta-b65)
Java HotSpot(TM) Client VM (build 1.4.0-beta-b65, mixed mode)
<das@horror(pts/7).286> /set/jdk-builds/JDK1.4.0beta-b65/solaris/bin/java Test
java.io.NotSerializableException: sun.awt.motif.X11Image
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1048)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1324)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1296)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1239)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1046)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:277)
at Test.main(Test.java:14)
The serialization fails as sun.awt.CustomCursor contains non-trainsient field of type Image.
======================================================================