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

TransferHandler is throwing NotSerializableException.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.4.0
    • 1.4.0
    • client-libs
    • beta
    • generic, x86, sparc
    • generic, solaris, solaris_8, windows_nt
    • Verified

      Run the following program and you should get the following message:

      java.io.NotSerializableException: javax.swing.TransferHandler$DropHandler
              at java.io.ObjectOutputStream.outputObject(ObjectOutputStream.java:1148)
              at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:366)
              at java.io.ObjectOutputStream.outputClassFields(ObjectOutputStream.java:1841)
              at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:480)
              at java.io.ObjectOutputStream.outputObject(ObjectOutputStream.java:1214)
              at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:366)
              at java.io.ObjectOutputStream.outputClassFields(ObjectOutputStream.java:1841)
              at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:480)
              at java.awt.Component.writeObject(Component.java:4842)
              at java.lang.reflect.Method.invoke(Native Method)
              at java.io.ObjectOutputStream.invokeObjectWriter(ObjectOutputStream.java:1878)
              at java.io.ObjectOutputStream.outputObject(ObjectOutputStream.java:1210)
              at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:366)
              at TestSerialize.serializeAndDeserialize(TestSerialize.java:29)
              at TestSerialize.<init>(TestSerialize.java:16)
              at TestSerialize.main(TestSerialize.java:9)

      This happens for the following components:

      DefaultCellEditor, JTextField, JList, JEditorPane, JTextArea, JPasswordField, JTextPane, TableColumn

      The TransferHandler class, which is for the new DnD feature, is not serializable which I assume is why these components are failing since all these components creates an instance of this object.


      ------------------------------------------------------------------------------
      import java.io.*;

      import javax.swing.*;
      import javax.swing.table.*;

      public class TestSerialize {

          public static void main(String[] args) {
              new TestSerialize();
          }

          public TestSerialize() {
              Object target = new JTextField();

              try {
                  serializeAndDeserialize(target);
              } catch(Exception e) {
                  e.printStackTrace();
              }

              System.exit(0);
          }

          private Object serializeAndDeserialize(Object toWrite)
              throws ClassNotFoundException, IOException {

              FileOutputStream fos = new FileOutputStream("cereal.dat");
              ObjectOutputStream oos = new ObjectOutputStream(fos);
              oos.writeObject(toWrite);
              oos.flush();
              fos.close();

              FileInputStream fis = new FileInputStream("cereal.dat");
              ObjectInputStream ois = new ObjectInputStream(fis);
              Object retVal = ois.readObject();
              fis.close();

              return retVal;
          }
      }
      ------------------------------------------------------------------------------



      edmund.lou@eng 2000-09-28
      --------------------------------------

            tprinzing Tim Prinzing (Inactive)
            elousunw Edmund Lou (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: