Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/EmbeddedFrame/DisplayChangedTest/DisplayChangedTest.java
38828 views
1
/*
2
* Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/*
25
@test
26
@bug 4980592
27
@summary switching user in XP causes an NPE in
28
sun.awt.windows.WWindowPeer.displayChanged
29
@requires (os.family == "windows")
30
@author [email protected]: area=embedded
31
@run main DisplayChangedTest
32
*/
33
/**
34
* DisplayChangedTest.java
35
*
36
* summary: switching user in XP causes an NPE in
37
* sun.awt.windows.WWindowPeer.displayChanged
38
*/
39
import java.awt.Frame;
40
import java.awt.Dialog;
41
import java.awt.TextArea;
42
import java.awt.peer.ComponentPeer;
43
import java.awt.peer.FramePeer;
44
import java.lang.reflect.Constructor;
45
import java.lang.reflect.Method;
46
import java.lang.reflect.Field;
47
48
import sun.awt.AWTAccessor;
49
50
public class DisplayChangedTest {
51
52
/**
53
* Test fails if it throws any exception.
54
*
55
* @throws Exception
56
*/
57
private void init() throws Exception {
58
59
if (!System.getProperty("os.name").startsWith("Windows")) {
60
System.out.println("This is Windows only test.");
61
return;
62
}
63
64
Frame frame = new Frame("AWT Frame");
65
frame.pack();
66
67
FramePeer frame_peer = (FramePeer) AWTAccessor.getComponentAccessor()
68
.getPeer(frame);
69
Class comp_peer_class = Class.forName("sun.awt.windows.WComponentPeer");
70
Field hwnd_field = comp_peer_class.getDeclaredField("hwnd");
71
hwnd_field.setAccessible(true);
72
long hwnd = hwnd_field.getLong(frame_peer);
73
74
Class clazz = Class.forName("sun.awt.windows.WEmbeddedFrame");
75
Constructor constructor = clazz
76
.getConstructor(new Class[]{long.class});
77
Frame embedded_frame = (Frame) constructor
78
.newInstance(new Object[]{new Long(hwnd)});
79
frame.setVisible(true);
80
81
ComponentPeer peer = AWTAccessor.getComponentAccessor().getPeer(
82
embedded_frame);
83
Class peerClass = peer.getClass();
84
Method displayChangedM = peerClass.getMethod("displayChanged",
85
new Class[0]);
86
displayChangedM.invoke(peer, null);
87
embedded_frame.dispose();
88
frame.dispose();
89
90
}
91
92
public static void main(String args[]) throws Exception {
93
new DisplayChangedTest().init();
94
}
95
96
}
97
98