Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/RepaintManager/7013453/bug7013453.java
38853 views
1
/*
2
* Copyright (c) 2011, 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
/* @test
25
@bug 7013453
26
@summary BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
27
@author Pavel Porvatov
28
*/
29
30
import javax.swing.*;
31
import java.lang.reflect.Field;
32
import java.lang.reflect.InvocationTargetException;
33
import java.lang.reflect.Method;
34
35
public class bug7013453 {
36
public static void main(String[] args) throws Exception {
37
SwingUtilities.invokeAndWait(new Runnable() {
38
public void run() {
39
try {
40
Method getPaintManagerMethod = RepaintManager.class.getDeclaredMethod("getPaintManager");
41
42
getPaintManagerMethod.setAccessible(true);
43
44
final Object paintManager = getPaintManagerMethod.invoke(RepaintManager.currentManager(new JLabel()));
45
46
String paintManagerName = paintManager.getClass().getCanonicalName();
47
48
if (!paintManagerName.equals("javax.swing.BufferStrategyPaintManager")) {
49
System.out.println("The test is not suitable for the " + paintManagerName +
50
" paint manager. The test skipped.");
51
52
return;
53
}
54
55
final Field showingField = paintManager.getClass().getDeclaredField("showing");
56
57
showingField.setAccessible(true);
58
59
synchronized (paintManager) {
60
showingField.setBoolean(paintManager, true);
61
}
62
63
// Postpone reset the showing field
64
Thread thread = new Thread(new Runnable() {
65
public void run() {
66
try {
67
Thread.sleep(500);
68
} catch (InterruptedException e) {
69
throw new RuntimeException(e);
70
}
71
72
synchronized (paintManager) {
73
try {
74
showingField.setBoolean(paintManager, false);
75
} catch (IllegalAccessException e) {
76
throw new RuntimeException(e);
77
}
78
}
79
}
80
});
81
82
thread.start();
83
84
Method disposeMethod = paintManager.getClass().getDeclaredMethod("dispose");
85
86
disposeMethod.setAccessible(true);
87
88
disposeMethod.invoke(paintManager);
89
90
System.out.println("The test passed.");
91
} catch (NoSuchMethodException e) {
92
throw new RuntimeException(e);
93
} catch (InvocationTargetException e) {
94
throw new RuntimeException(e);
95
} catch (IllegalAccessException e) {
96
throw new RuntimeException(e);
97
} catch (NoSuchFieldException e) {
98
throw new RuntimeException(e);
99
}
100
}
101
});
102
}
103
}
104
105