Path: blob/master/test/jdk/javax/swing/JFrame/Serialization/JFrameMenuSerializationTest.java
41153 views
/*1* Copyright (c) 2017, 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 818920127* @summary [macosx] NotSerializableException during JFrame with MenuBar28* serialization29* @run main JFrameMenuSerializationTest30*/3132import javax.swing.*;33import java.awt.*;34import java.beans.PropertyChangeEvent;35import java.beans.PropertyChangeListener;36import java.io.ByteArrayOutputStream;37import java.io.IOException;38import java.io.NotSerializableException;39import java.io.ObjectOutputStream;4041public class JFrameMenuSerializationTest {42private static JFrame frame;4344public static void main(String[] args) throws Exception {45System.setProperty("apple.laf.useScreenMenuBar", "true");46SwingUtilities.invokeAndWait(() -> {47frame = new JFrame();48frame.setJMenuBar(new JMenuBar());49frame.setVisible(true);50frame.getAccessibleContext().addPropertyChangeListener(evt -> {});51});52Robot robot = new Robot();53robot.waitForIdle();54robot.delay(200);55ByteArrayOutputStream baos = new ByteArrayOutputStream(10000);56ObjectOutputStream oos = new ObjectOutputStream(baos);57SwingUtilities.invokeAndWait(() -> {58try {59oos.writeObject(frame);60} catch (NotSerializableException e) {61throw new RuntimeException("Test failed", e);62} catch (IOException e) {63e.printStackTrace();64}65});66SwingUtilities.invokeLater(frame::dispose);6768}69}707172