Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/AncestorNotifier/7193219/bug7193219.java
38855 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/* @test24@bug 719321925@summary JComboBox serialization fails in JDK 1.726@author Anton Litvinov27*/2829import java.io.*;3031import javax.swing.*;32import javax.swing.plaf.metal.*;3334public class bug7193219 {35private static byte[] serializeGUI() {36// Create and set up the window.37JFrame frame = new JFrame("Serialization");38JPanel mainPanel = new JPanel();3940/**41* If JComboBox is replaced with other component like JLabel42* The issue does not happen.43*/44JComboBox status = new JComboBox();45status.addItem("123");46mainPanel.add(status);47frame.getContentPane().add(mainPanel);48frame.pack();4950try {51ByteArrayOutputStream baos = new ByteArrayOutputStream();52ObjectOutputStream oos = new ObjectOutputStream(baos);53oos.writeObject(mainPanel);54oos.flush();55frame.dispose();56return baos.toByteArray();57} catch (IOException ioe) {58throw new RuntimeException(ioe);59}60}6162private static void deserializeGUI(byte[] serializedData) {63try {64ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(serializedData));65JPanel mainPanel = (JPanel)ois.readObject();66JFrame frame = new JFrame("Deserialization");67frame.getContentPane().add(mainPanel);68frame.pack();69frame.dispose();70} catch (Exception e) {71throw new RuntimeException(e);72}73}7475public static void main(String[] args) throws Exception {76UIManager.setLookAndFeel(new MetalLookAndFeel());77SwingUtilities.invokeAndWait(new Runnable() {78@Override79public void run() {80deserializeGUI(serializeGUI());81}82});83}84}858687