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

Editing JTable is not Serializable

    XMLWordPrintable

    Details

      Description

      FULL PRODUCT VERSION :
      Java(TM) SE Runtime Environment (build 1.6.0-beta2-b77)

      ADDITIONAL OS VERSION INFORMATION :
      Should be independent

      A DESCRIPTION OF THE PROBLEM :
      The JTable if it is editing is not Serializable. When it is not editing, it is Serializable. The fix must check that all the default editors are Serializable and any additional objects in action during editing.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run this test, it will blow up on the editing JTable but will serialize on the non-editing one:
      import javax.swing.*;
      import javax.swing.table.*;
      import java.io.*;

      public class EditingJTableNotSerializable implements Runnable{

          public void run(){
              Object[][] data = new Object[][]{ new Object[]{ 1,2,3,4,5}};
              Object[] names = new Object[]{ 1,2,3,4,5};
              JTable jt = new JTable(data, names);
              jt.editCellAt(0,0);
              System.out.println("Serializing editing JTable");
              serialize(jt);
              TableCellEditor tce = jt.getCellEditor();
              tce.stopCellEditing();
              System.out.println("Serializing non-editing JTable");
              serialize(jt);

          }

      void serialize(JTable jt){
              try{
                  ByteArrayOutputStream baos = new ByteArrayOutputStream();
                  ObjectOutputStream oos = new ObjectOutputStream(baos);
                  oos.writeObject(jt);
                  byte[] bdata = baos.toByteArray();
                  ByteArrayInputStream bais = new ByteArrayInputStream(bdata);
                  ObjectInputStream ois = new ObjectInputStream(bais);
                  ois.readObject();
              }
              catch(Exception x){ x.printStackTrace(); }

          }




          public static void main(String ... args){
      SwingUtilities.invokeLater(new EditingJTableNotSerializable());
          }
      }

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Serialzation
      ACTUAL -
      An Exception is printed out

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      java.io.NotSerializableException: java.lang.reflect.Constructor
              at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1149) at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1502)
              at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1467)
              at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1385)
              at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1143) at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1502)
              at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1467)
              at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1385)
              at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1143) at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:325)
              at javax.swing.event.EventListenerList.writeObject(EventListenerList.java:240)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
              at java.lang.reflect.Method.invoke(Method.java:589)
              at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:944)
              at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1454)
              at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1385)
              at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1143) at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1502)
              at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:414)
              at javax.swing.JComponent.writeObject(JComponent.java:5385)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
              at java.lang.reflect.Method.invoke(Method.java:589)
              at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:944)
              at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1454)
              at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1385)
              at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1143) at java.io.ObjectOutputStream.writeArray(ObjectOutputStream.java:1331)
              at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1139) at java.io.ObjectOutputStream.access$300(ObjectOutputStream.java:143)
              at java.io.ObjectOutputStream$PutFieldImpl.writeFields(ObjectOutputStream.java:1658)
              at java.io.ObjectOutputStream.writeFields(ObjectOutputStream.java:452)
              at java.awt.Container.writeObject(Container.java:3479)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
              at java.lang.reflect.Method.invoke(Method.java:589)
              at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:944)
              at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1454)
              at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1385)
              at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1143) at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:325)
              at EditingJTableNotSerializable.serialize(EditingJTableNotSerializable.java:25)
              at EditingJTableNotSerializable.run(EditingJTableNotSerializable.java:13)
              at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
              at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
              at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
              at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
              at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
              at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160) at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.swing.*;
      import javax.swing.table.*;
      import java.io.*;

      public class EditingJTableNotSerializable implements Runnable{

          public void run(){
              Object[][] data = new Object[][]{ new Object[]{ 1,2,3,4,5}};
              Object[] names = new Object[]{ 1,2,3,4,5};
              JTable jt = new JTable(data, names);
              jt.editCellAt(0,0);
              System.out.println("Serializing editing JTable");
              serialize(jt);
              TableCellEditor tce = jt.getCellEditor();
              tce.stopCellEditing();
              System.out.println("Serializing non-editing JTable");
              serialize(jt);

          }

      void serialize(JTable jt){
              try{
                  ByteArrayOutputStream baos = new ByteArrayOutputStream();
                  ObjectOutputStream oos = new ObjectOutputStream(baos);
                  oos.writeObject(jt);
                  byte[] bdata = baos.toByteArray();
                  ByteArrayInputStream bais = new ByteArrayInputStream(bdata);
                  ObjectInputStream ois = new ObjectInputStream(bais);
                  ois.readObject();
              }
              catch(Exception x){ x.printStackTrace(); }

          }




          public static void main(String ... args){
      SwingUtilities.invokeLater(new EditingJTableNotSerializable());
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      There isn't one except to override Serialization for the JTable and that might not be a possibility. The user would have to stop editing to Serialize, which may not be what they want to do.

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            gmanwanisunw Girish Manwani (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Imported:
              Indexed: