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

Serialization corrupts JComboBox

    XMLWordPrintable

    Details

      Description

      FULL PRODUCT VERSION :
      java version "1.6.0"
      Java(TM) SE Runtime Environment (build 1.6.0-b105)
      Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      The problem also happens under JRE 1.5.0

      A DESCRIPTION OF THE PROBLEM :
      Serializing a frame that contains a JComboBox with a custom editor leads an exception (see the Error Messages field). It appears that the UI delegate is being uninstalled during serialization and not reinstalled. This may be related to bug 5081305.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the attached Java program
      In the UI that appears click the "Serialize" button
      Observe the exception

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      No exception
      ACTUAL -
      Exception

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
              at javax.swing.plaf.basic.BasicComboBoxUI.paint(BasicComboBoxUI.java:846)
              at javax.swing.plaf.ComponentUI.update(ComponentUI.java:142)
              at javax.swing.JComponent.paintComponent(JComponent.java:742)
              at javax.swing.JComponent.paint(JComponent.java:1005)
              at javax.swing.JComponent.paintWithOffscreenBuffer(JComponent.java:4963)
              at javax.swing.JComponent.paintDoubleBuffered(JComponent.java:4916)
              at javax.swing.JComponent._paintImmediately(JComponent.java:4859)
              at javax.swing.JComponent.paintImmediately(JComponent.java:4666)
              at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:451)
              at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.
      java:114)
              at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
              at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)
              at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
              at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
              at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
              at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
              at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.*;
      import java.awt.event.*;
      import java.io.*;
      import javax.swing.*;
      import javax.swing.plaf.basic.*;

      public class SerializationProblem
      {
          public static void main(String[] args) {

              try {UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());}
              catch (Exception e) {}

              final JFrame frame = new JFrame("Serialization Problem");
              JComboBox comboBox = new JComboBox(new Object[] {"Item 1", "Item 2", "Item 3"});
              JButton button = new JButton("Serialize");

              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              comboBox.setEditor(new CustomEditor());

              button.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent event) {
                      try {
                          FileOutputStream fileOut = new FileOutputStream("temp.dat");
                          ObjectOutputStream objectOut = new ObjectOutputStream(fileOut);
                          objectOut.writeObject(frame);
                          objectOut.close();
                          fileOut.close();
                      } catch (IOException ioe) {}
                  }
              });

              frame.getContentPane().add(comboBox, BorderLayout.NORTH);
              frame.getContentPane().add(button, BorderLayout.SOUTH);

              frame.pack();
              frame.setVisible(true);
          }

          static class CustomEditor extends BasicComboBoxEditor //.UIResource // Uncommenting this prevents the problem
          {
              CustomEditor() {editor = new JTextField(15);}
          }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Tagging the custom editor as a UIResource prevents the problem but this isn't always desirable.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              igor Igor Nekrestyanov (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Imported:
                Indexed: