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

Custom cursor cannot be serialized

    Details

    • Type: Bug
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 1.4.0
    • Fix Version/s: None
    • Component/s: client-libs
    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description



      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.

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

        Attachments

          Activity

            People

            • Assignee:
              denis Denis Fokin (Inactive)
              Reporter:
              dassunw Das Das (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Imported:
                Indexed: