author | ssadetsky |
Wed, 03 Apr 2019 15:43:25 -0700 | |
branch | JDK-8200758-branch |
changeset 57303 | eff0cf668c29 |
parent 49090 | 82c1fe23c469 |
permissions | -rw-r--r-- |
48726
4b622ca57277
8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents:
diff
changeset
|
1 |
/* |
4b622ca57277
8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents:
diff
changeset
|
2 |
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. |
4b622ca57277
8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4b622ca57277
8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents:
diff
changeset
|
4 |
* |
4b622ca57277
8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
4b622ca57277
8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
4b622ca57277
8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
4b622ca57277
8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents:
diff
changeset
|
8 |
* |
4b622ca57277
8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
4b622ca57277
8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
4b622ca57277
8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
4b622ca57277
8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
4b622ca57277
8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents:
diff
changeset
|
13 |
* accompanied this code). |
4b622ca57277
8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents:
diff
changeset
|
14 |
* |
4b622ca57277
8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
4b622ca57277
8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
4b622ca57277
8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
4b622ca57277
8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents:
diff
changeset
|
18 |
* |
4b622ca57277
8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
4b622ca57277
8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
4b622ca57277
8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents:
diff
changeset
|
21 |
* questions. |
4b622ca57277
8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents:
diff
changeset
|
22 |
*/ |
4b622ca57277
8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents:
diff
changeset
|
23 |
|
4b622ca57277
8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents:
diff
changeset
|
24 |
/** |
4b622ca57277
8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents:
diff
changeset
|
25 |
* @test |
49090
82c1fe23c469
8196196: Headful tests should not be run in headless mode
serb
parents:
48726
diff
changeset
|
26 |
* @key headful |
48726
4b622ca57277
8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents:
diff
changeset
|
27 |
* @bug 8189201 |
4b622ca57277
8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents:
diff
changeset
|
28 |
* @summary [macosx] NotSerializableException during JFrame with MenuBar |
4b622ca57277
8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents:
diff
changeset
|
29 |
* serialization |
4b622ca57277
8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents:
diff
changeset
|
30 |
* @run main JFrameMenuSerializationTest |
4b622ca57277
8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents:
diff
changeset
|
31 |
*/ |
4b622ca57277
8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents:
diff
changeset
|
32 |
|
4b622ca57277
8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents:
diff
changeset
|
33 |
import javax.swing.*; |
4b622ca57277
8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents:
diff
changeset
|
34 |
import java.awt.*; |
4b622ca57277
8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents:
diff
changeset
|
35 |
import java.beans.PropertyChangeEvent; |
4b622ca57277
8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents:
diff
changeset
|
36 |
import java.beans.PropertyChangeListener; |
4b622ca57277
8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents:
diff
changeset
|
37 |
import java.io.ByteArrayOutputStream; |
4b622ca57277
8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents:
diff
changeset
|
38 |
import java.io.IOException; |
4b622ca57277
8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents:
diff
changeset
|
39 |
import java.io.NotSerializableException; |
4b622ca57277
8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents:
diff
changeset
|
40 |
import java.io.ObjectOutputStream; |
4b622ca57277
8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents:
diff
changeset
|
41 |
|
4b622ca57277
8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents:
diff
changeset
|
42 |
public class JFrameMenuSerializationTest { |
4b622ca57277
8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents:
diff
changeset
|
43 |
private static JFrame frame; |
4b622ca57277
8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents:
diff
changeset
|
44 |
|
4b622ca57277
8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents:
diff
changeset
|
45 |
public static void main(String[] args) throws Exception { |
4b622ca57277
8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents:
diff
changeset
|
46 |
System.setProperty("apple.laf.useScreenMenuBar", "true"); |
4b622ca57277
8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents:
diff
changeset
|
47 |
SwingUtilities.invokeAndWait(() -> { |
4b622ca57277
8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents:
diff
changeset
|
48 |
frame = new JFrame(); |
4b622ca57277
8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents:
diff
changeset
|
49 |
frame.setJMenuBar(new JMenuBar()); |
4b622ca57277
8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents:
diff
changeset
|
50 |
frame.setVisible(true); |
4b622ca57277
8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents:
diff
changeset
|
51 |
frame.getAccessibleContext().addPropertyChangeListener(evt -> {}); |
4b622ca57277
8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents:
diff
changeset
|
52 |
}); |
4b622ca57277
8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents:
diff
changeset
|
53 |
Robot robot = new Robot(); |
4b622ca57277
8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents:
diff
changeset
|
54 |
robot.waitForIdle(); |
4b622ca57277
8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents:
diff
changeset
|
55 |
robot.delay(200); |
4b622ca57277
8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents:
diff
changeset
|
56 |
ByteArrayOutputStream baos = new ByteArrayOutputStream(10000); |
4b622ca57277
8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents:
diff
changeset
|
57 |
ObjectOutputStream oos = new ObjectOutputStream(baos); |
4b622ca57277
8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents:
diff
changeset
|
58 |
SwingUtilities.invokeAndWait(() -> { |
4b622ca57277
8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents:
diff
changeset
|
59 |
try { |
4b622ca57277
8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents:
diff
changeset
|
60 |
oos.writeObject(frame); |
4b622ca57277
8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents:
diff
changeset
|
61 |
} catch (NotSerializableException e) { |
4b622ca57277
8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents:
diff
changeset
|
62 |
throw new RuntimeException("Test failed", e); |
4b622ca57277
8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents:
diff
changeset
|
63 |
} catch (IOException e) { |
4b622ca57277
8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents:
diff
changeset
|
64 |
e.printStackTrace(); |
4b622ca57277
8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents:
diff
changeset
|
65 |
} |
4b622ca57277
8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents:
diff
changeset
|
66 |
}); |
4b622ca57277
8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents:
diff
changeset
|
67 |
SwingUtilities.invokeLater(frame::dispose); |
4b622ca57277
8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents:
diff
changeset
|
68 |
|
4b622ca57277
8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents:
diff
changeset
|
69 |
} |
4b622ca57277
8189201: [macosx] NotSerializableException during JFrame with MenuBar serialization
ssadetsky
parents:
diff
changeset
|
70 |
} |