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

JComponents with non-null TransferHandlers are not Serializable

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P2 P2
    • 1.4.0
    • 1.4.0
    • client-libs
    • None
    • beta
    • generic
    • generic
    • Verified

      In merlin, the field 'private TransferHandler transfer' was added to JComponent.
      TransferHandler is not Serializable, so if its value is non-null, a JComponent
      cannot be serialized.

      import javax.swing.*;
      import java.io.*;

      public class JComponentSerializationTest {
          public static void main(String[] args) throws Exception {
      JComponent jcomp = new JLabel();
      jcomp.setTransferHandler(new TransferHandler("text"));

      FileOutputStream fos = new FileOutputStream(new File("tmp"));
      ObjectOutputStream oos = new ObjectOutputStream(fos);

      oos.writeObject(jcomp);
          }
      }

      Exception in thread "main" java.io.NotSerializableException
              at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1007)
              at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1291)
              at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:367)
              at javax.swing.JComponent.writeObject(JComponent.java:4747)
              at sun.misc.Unsafe.invokeSpecial(Native Method)
              at sun.misc.ClassReflector.invokeSpecial(ClassReflector.java:376)
              at $ClassReflector1.writeObject(Unknown Source)
              at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1260)
              at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1209)
              at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1005)
              at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:278)
              at JComponentSerializationTest.main(JComponentSerializationTest.java:12)

      The field needs to be made transient, and an attempt made to serialze it in
      writeObject iff it is Serializable.

            tprinzing Tim Prinzing (Inactive)
            dmendenhsunw David Mendenhall (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: