Path: blob/master/test/jdk/javax/swing/AncestorNotifier/7193219/bug7193219.java
41155 views
/*1* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @key headful26* @bug 719321927* @summary JComboBox serialization fails in JDK 1.728* @author Anton Litvinov29*/3031import java.io.*;3233import javax.swing.*;34import javax.swing.plaf.metal.*;3536public class bug7193219 {37private static byte[] serializeGUI() {38// Create and set up the window.39JFrame frame = new JFrame("Serialization");40JPanel mainPanel = new JPanel();4142/**43* If JComboBox is replaced with other component like JLabel44* The issue does not happen.45*/46JComboBox status = new JComboBox();47status.addItem("123");48mainPanel.add(status);49frame.getContentPane().add(mainPanel);50frame.pack();5152try {53ByteArrayOutputStream baos = new ByteArrayOutputStream();54ObjectOutputStream oos = new ObjectOutputStream(baos);55oos.writeObject(mainPanel);56oos.flush();57frame.dispose();58return baos.toByteArray();59} catch (IOException ioe) {60throw new RuntimeException(ioe);61}62}6364private static void deserializeGUI(byte[] serializedData) {65try {66ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(serializedData));67JPanel mainPanel = (JPanel)ois.readObject();68JFrame frame = new JFrame("Deserialization");69frame.getContentPane().add(mainPanel);70frame.pack();71frame.dispose();72} catch (Exception e) {73throw new RuntimeException(e);74}75}7677public static void main(String[] args) throws Exception {78UIManager.setLookAndFeel(new MetalLookAndFeel());79SwingUtilities.invokeAndWait(new Runnable() {80@Override81public void run() {82deserializeGUI(serializeGUI());83}84});85}86}878889