jdk/test/javax/swing/AncestorNotifier/7193219/bug7193219.java
author hseigel
Wed, 01 Mar 2017 08:00:02 -0500
changeset 46194 5596e6f63072
parent 40128 e635645d2a8a
permissions -rw-r--r--
8172307: Remove ununsed JVM API JVM_GetModuleByPackageName() Summary: Remove get_module_by_package_name() etc., and unneeded test. Reviewed-by: sspitsyn, gtriantafill
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14303
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
     1
/*
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
     2
 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
     4
 *
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
     7
 * published by the Free Software Foundation.
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
     8
 *
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
    13
 * accompanied this code).
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
    14
 *
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
    18
 *
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
    21
 * questions.
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
    22
 */
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
    23
40128
e635645d2a8a 8160974: [TESTBUG] Mark more headful tests with @key headful.
goetz
parents: 14891
diff changeset
    24
/*
e635645d2a8a 8160974: [TESTBUG] Mark more headful tests with @key headful.
goetz
parents: 14891
diff changeset
    25
 * @test
e635645d2a8a 8160974: [TESTBUG] Mark more headful tests with @key headful.
goetz
parents: 14891
diff changeset
    26
 * @key headful
e635645d2a8a 8160974: [TESTBUG] Mark more headful tests with @key headful.
goetz
parents: 14891
diff changeset
    27
 * @bug 7193219
e635645d2a8a 8160974: [TESTBUG] Mark more headful tests with @key headful.
goetz
parents: 14891
diff changeset
    28
 * @summary JComboBox serialization fails in JDK 1.7
e635645d2a8a 8160974: [TESTBUG] Mark more headful tests with @key headful.
goetz
parents: 14891
diff changeset
    29
 * @author Anton Litvinov
e635645d2a8a 8160974: [TESTBUG] Mark more headful tests with @key headful.
goetz
parents: 14891
diff changeset
    30
 */
14303
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
    31
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
    32
import java.io.*;
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
    33
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
    34
import javax.swing.*;
14891
9d205107de0b 8003982: new test javax/swing/AncestorNotifier/7193219/bug7193219.java failed on macosx
alexp
parents: 14303
diff changeset
    35
import javax.swing.plaf.metal.*;
14303
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
    36
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
    37
public class bug7193219 {
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
    38
    private static byte[] serializeGUI() {
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
    39
        // Create and set up the window.
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
    40
        JFrame frame = new JFrame("Serialization");
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
    41
        JPanel mainPanel = new JPanel();
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
    42
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
    43
        /**
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
    44
         * If JComboBox is replaced with other component like JLabel
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
    45
         * The issue does not happen.
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
    46
         */
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
    47
        JComboBox status = new JComboBox();
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
    48
        status.addItem("123");
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
    49
        mainPanel.add(status);
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
    50
        frame.getContentPane().add(mainPanel);
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
    51
        frame.pack();
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
    52
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
    53
        try {
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
    54
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
    55
            ObjectOutputStream oos = new ObjectOutputStream(baos);
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
    56
            oos.writeObject(mainPanel);
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
    57
            oos.flush();
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
    58
            frame.dispose();
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
    59
            return baos.toByteArray();
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
    60
        } catch (IOException ioe) {
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
    61
            throw new RuntimeException(ioe);
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
    62
        }
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
    63
    }
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
    64
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
    65
    private static void deserializeGUI(byte[] serializedData) {
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
    66
        try {
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
    67
            ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(serializedData));
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
    68
            JPanel mainPanel = (JPanel)ois.readObject();
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
    69
            JFrame frame = new JFrame("Deserialization");
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
    70
            frame.getContentPane().add(mainPanel);
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
    71
            frame.pack();
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
    72
            frame.dispose();
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
    73
        } catch (Exception e) {
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
    74
            throw new RuntimeException(e);
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
    75
        }
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
    76
    }
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
    77
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
    78
    public static void main(String[] args) throws Exception {
14891
9d205107de0b 8003982: new test javax/swing/AncestorNotifier/7193219/bug7193219.java failed on macosx
alexp
parents: 14303
diff changeset
    79
        UIManager.setLookAndFeel(new MetalLookAndFeel());
14303
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
    80
        SwingUtilities.invokeAndWait(new Runnable() {
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
    81
            @Override
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
    82
            public void run() {
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
    83
                deserializeGUI(serializeGUI());
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
    84
            }
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
    85
        });
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
    86
    }
de2b26a9e1c3 7193219: JComboBox serialization fails in JDK 1.7
alitvinov
parents:
diff changeset
    87
}