United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-8001982 JComboBox serialization fails in JDK 1.7
JDK-8001982 : JComboBox serialization fails in JDK 1.7

Details
Type:
Backport
Submit Date:
2012-10-30
Status:
Closed
Updated Date:
2012-11-28
Project Name:
JDK
Resolved Date:
2012-11-15
Component:
client-libs
OS:
Sub-Component:
java.awt
CPU:
Priority:
P2
Resolution:
Fixed
Affected Versions:
7
Fixed Versions:
7u10 (b17)

Related Reports
Backport:

Sub Tasks

Description
FULL PRODUCT VERSION :
java version "1.7.0_05"
Java(TM) SE Runtime Environment (build 1.7.0_05-b06)
Java HotSpot(TM) Client VM (build 23.1-b03, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows and Oracle Solaris

A DESCRIPTION OF THE PROBLEM :
Deserialization of java.awt.Container, which has JComboBox and which was previously added to JFrame, produces NullPointerException on JDK 1.7, while on JDK 1.6 and 1.5 it does not.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile and run the attached source code.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Both windows with titles ???why why why ??? and ???deserialize ??? and with identical contents should be displayed on the desktop. No exception should be thrown.
ACTUAL -
NullPointerException is thrown (see below).

ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.lang.NullPointerException
         at java.awt.Container.updateGraphicsData(Container.java:1149)
         at java.awt.Container.updateGraphicsData(Container.java:1151)
         at java.awt.Container.updateGraphicsData(Container.java:1151)
         at java.awt.Container.updateGraphicsData(Container.java:1151)
         at java.awt.Container.updateGraphicsData(Container.java:1151)
         at java.awt.Component.setGraphicsConfiguration(Component.java:1152)
         at java.awt.Window.setGraphicsConfiguration(Window.java:3144)
         at java.awt.Window.initGC(Window.java:470)
         at java.awt.Window.initDeserializedWindow(Window.java:2954)
         at java.awt.Window.readObject(Window.java:3042)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
         at java.lang.reflect.Method.invoke(Method.java:601)
         at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:1004)
         at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1866)

         at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1771)
         at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
         at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1964)
         at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1888)

         at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1771)
         at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
         at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369)
         at java.beans.PropertyChangeSupport.readObject(PropertyChangeSupport.java:468)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
         at java.lang.reflect.Method.invoke(Method.java:601)
         at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:1004)
         at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1866)

         at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1771)
         at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
         at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1964)
         at java.io.ObjectInputStream.defaultReadObject(ObjectInputStream.java:498)
         at java.awt.Component.readObject(Component.java:8681)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
         at java.lang.reflect.Method.invoke(Method.java:601)
         at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:1004)
         at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1866)

         at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1771)
         at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
         at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369)
         at MainTest.test(MainTest.java:65)
         at MainTest.access$100(MainTest.java:15)
         at MainTest$1.run(MainTest.java:91)
         at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
         at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:701)
         at java.awt.EventQueue.access$000(EventQueue.java:102)
         at java.awt.EventQueue$3.run(EventQueue.java:662)
         at java.awt.EventQueue$3.run(EventQueue.java:660)
         at java.security.AccessController.doPrivileged(Native Method)
         at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
         at java.awt.EventQueue.dispatchEvent(EventQueue.java:671)
         at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:244)
         at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:163)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:147)

         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:139)

         at java.awt.EventDispatchThread.run(EventDispatchThread.java:97)

REPRODUCIBILITY :
---------- BEGIN SOURCE ----------
import java.awt.BorderLayout;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInput;
import java.io.ObjectInputStream;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class MainTest
{

    private static void createAndShowGUI()
    {
        //Create and set up the window.
        JFrame frame = new JFrame("HelloWorldSwing");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setTitle("why why why");
        JPanel mainPanel = new JPanel(new BorderLayout());

        /**
         * If replace JComboBox with other component like JLabel
         * There is no issue happen.
         */
        JComboBox status = new JComboBox();
        status.addItem("123");
       
//        JButton btn = new JButton("456");

        mainPanel.add(new JLabel("xxx"), BorderLayout.NORTH);
        mainPanel.add(status, BorderLayout.SOUTH);
        frame.getContentPane().add(mainPanel);

        //Display the window.
        frame.pack();
        frame.setVisible(true);

        FileOutputStream f;
        try
        {
            f = new FileOutputStream("tmp.vt");
            ObjectOutput s = new ObjectOutputStream(f);
            s.writeObject(mainPanel);
            s.flush();
            s.close();
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }

    private static void test()
    {
        FileInputStream f;
        try
        {
            f = new FileInputStream("tmp.vt");
            ObjectInput s = new ObjectInputStream(f);
            JPanel mp = (JPanel) s.readObject();
            JFrame frame = new JFrame();
            frame.getContentPane().add(mp);
            frame.setTitle("deserialize");
            frame.pack();
            frame.setVisible(true);
            s.close();
            f.close();
        }
        catch (Exception e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

    public static void main(String[] args)
    {
        //Schedule a job for the event-dispatching thread:
        //creating and showing this application's GUI.
        javax.swing.SwingUtilities.invokeLater(new Runnable()
        {
            public void run()
            {
                createAndShowGUI();
                test();
            }
        });
    }
}
---------- END SOURCE ----------

                                    

Comments
Fix from 7u9-b32 revision. If not included into 7u10, will need a sync revision on 7u10 and then on 7u11 and finally fix will go to public via 7u12. If fixed in 7u10, will get to public release quicker.
                                     
2012-10-30
What is the impact of not taking this fix? We would like to restrict the fixes going into 7u10 from on.
                                     
2012-11-05
Hello Anita,

I suppose that if the fix is not taken into JDK 7u10, there will be a situation, when this bug will become closed in JDK 7u9, then it will be reopened in JDK 7u10, 7u11, and will be considered as not reproducible in JDK 7u12. If such a scenario happens than the original integration of the fix into JDK 7u9 as a revision will look illogical.

Thank you,
Anton
                                     
2012-11-06
SQE is ok to take it in 7u10.
                                     
2012-11-07
/test: http://closedjdk.us.oracle.com/jdk7u/jdk7u10-dev/jdk/file/edc9e5fad5b0/test/javax/swing/AncestorNotifier/7193219/bug7193219.java
                                     
2012-11-19



Hardware and Software, Engineered to Work Together