author | pchelko |
Thu, 24 Apr 2014 20:58:00 +0400 | |
changeset 25532 | 6f9d3cf6ca39 |
permissions | -rw-r--r-- |
25532
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
1 |
/* |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
2 |
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
4 |
* |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
8 |
* |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
13 |
* accompanied this code). |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
14 |
* |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
18 |
* |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
21 |
* questions. |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
22 |
*/ |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
23 |
|
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
24 |
/** |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
25 |
* @test |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
26 |
* @bug 8032960 |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
27 |
* @summary checks that desktop properties work if Toolkit thread has no AppContext |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
28 |
* @author Petr Pchelko |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
29 |
*/ |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
30 |
|
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
31 |
import sun.awt.OSInfo; |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
32 |
import sun.awt.SunToolkit; |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
33 |
|
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
34 |
import javax.swing.*; |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
35 |
import java.awt.*; |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
36 |
import java.util.concurrent.atomic.AtomicBoolean; |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
37 |
import java.util.concurrent.atomic.AtomicReference; |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
38 |
|
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
39 |
public class NoAppContextTest { |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
40 |
|
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
41 |
private static final ThreadGroup stubGroup = new ThreadGroup("stub"); |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
42 |
private static final ThreadGroup awtGroup = new ThreadGroup("AWT"); |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
43 |
private static final AtomicBoolean propertyChangeFired = new AtomicBoolean(false); |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
44 |
private static Frame frame; |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
45 |
|
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
46 |
private static final Object LOCK = new Object(); |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
47 |
|
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
48 |
public static void main(String[] args) throws Exception { |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
49 |
|
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
50 |
if (OSInfo.getOSType() != OSInfo.OSType.WINDOWS) { |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
51 |
// The test is for Windows platform only |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
52 |
return; |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
53 |
} |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
54 |
|
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
55 |
createStubContext(); |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
56 |
|
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
57 |
Thread awtThread = new Thread(awtGroup, () -> { |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
58 |
SunToolkit.createNewAppContext(); |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
59 |
SwingUtilities.invokeLater(() -> { |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
60 |
synchronized (LOCK) { |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
61 |
frame = new Frame(); |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
62 |
frame.setBounds(100, 100, 100, 100); |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
63 |
frame.setVisible(true); |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
64 |
Toolkit.getDefaultToolkit().addPropertyChangeListener("win.propNames", ev -> { |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
65 |
propertyChangeFired.set(true); |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
66 |
}); |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
67 |
} |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
68 |
}); |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
69 |
}); |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
70 |
awtThread.start(); |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
71 |
awtThread.join(); |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
72 |
sync(); |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
73 |
|
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
74 |
final GraphicsDevice device = GraphicsEnvironment.getLocalGraphicsEnvironment() |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
75 |
.getDefaultScreenDevice(); |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
76 |
|
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
77 |
AtomicReference<DisplayMode> originalRef = new AtomicReference<>(); |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
78 |
try { |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
79 |
AtomicBoolean isSupported = new AtomicBoolean(true); |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
80 |
invokeInAWT(() -> { |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
81 |
if (device.isFullScreenSupported()) { |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
82 |
device.setFullScreenWindow(frame); |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
83 |
} else { |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
84 |
isSupported.set(false); |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
85 |
} |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
86 |
}); |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
87 |
if (!isSupported.get()) { |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
88 |
return; |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
89 |
} |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
90 |
invokeInAWT(() -> { |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
91 |
if (device.isDisplayChangeSupported()) { |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
92 |
DisplayMode original = device.getDisplayMode(); |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
93 |
originalRef.set(original); |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
94 |
try { |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
95 |
DisplayMode[] modes = device.getDisplayModes(); |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
96 |
for (DisplayMode mode : modes) { |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
97 |
if (!mode.equals(original)) { |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
98 |
device.setDisplayMode(mode); |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
99 |
break; |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
100 |
} |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
101 |
} |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
102 |
} finally { |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
103 |
device.setDisplayMode(original); |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
104 |
} |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
105 |
} else { |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
106 |
isSupported.set(false); |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
107 |
} |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
108 |
}); |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
109 |
if (!isSupported.get()) { |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
110 |
return; |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
111 |
} |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
112 |
} finally { |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
113 |
invokeInAWT(() -> { |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
114 |
device.setDisplayMode(originalRef.get()); |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
115 |
frame.dispose(); |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
116 |
}); |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
117 |
} |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
118 |
|
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
119 |
if (!propertyChangeFired.get()) { |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
120 |
throw new RuntimeException("Failed: PropertyChange did not fire"); |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
121 |
} |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
122 |
} |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
123 |
|
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
124 |
private static void invokeInAWT(Runnable r) throws InterruptedException { |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
125 |
Thread awtThread = new Thread(awtGroup, () -> { |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
126 |
SwingUtilities.invokeLater(() -> { |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
127 |
synchronized (LOCK) { |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
128 |
r.run(); |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
129 |
} |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
130 |
}); |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
131 |
}); |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
132 |
awtThread.start(); |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
133 |
awtThread.join(); |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
134 |
sync(); |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
135 |
} |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
136 |
|
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
137 |
private static void createStubContext() throws InterruptedException { |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
138 |
Thread stub = new Thread(stubGroup, SunToolkit::createNewAppContext); |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
139 |
stub.start(); |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
140 |
stub.join(); |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
141 |
} |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
142 |
|
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
143 |
/** |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
144 |
* Runs realSync on a thread with an AppContext and waits for it to finish |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
145 |
*/ |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
146 |
private static void sync() throws InterruptedException { |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
147 |
final AtomicReference<InterruptedException> exc = new AtomicReference<>(null); |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
148 |
|
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
149 |
Thread syncThread = new Thread(awtGroup, () -> { |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
150 |
try { |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
151 |
((SunToolkit) Toolkit.getDefaultToolkit()).realSync(); |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
152 |
Thread.sleep(2000); |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
153 |
} catch (InterruptedException e) { |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
154 |
exc.set(e); |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
155 |
} |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
156 |
}); |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
157 |
syncThread.start(); |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
158 |
syncThread.join(); |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
159 |
if (exc.get() != null) { |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
160 |
throw exc.get(); |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
161 |
} |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
162 |
} |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
163 |
} |
6f9d3cf6ca39
8032960: Running forms URL throws NullPointerException in Javaconsole.
pchelko
parents:
diff
changeset
|
164 |