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/imageio/AppContextTest.java
38833 views
1
/*
2
* Copyright (c) 2001, 2017, 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 4421190
27
* @summary Tests that Image I/O statics may be referenced properly from
28
* multiple AppContexts, as would be the case for multiple Applets in a
29
* single VM. Each AppContext should get its own copy of the registry
30
* and the caching parameters in the ImageIO class.
31
*/
32
33
import java.io.File;
34
import java.io.IOException;
35
36
import javax.imageio.ImageIO;
37
import javax.imageio.spi.IIORegistry;
38
39
import sun.awt.SunToolkit;
40
41
class TestThread extends Thread {
42
43
IIORegistry registry;
44
boolean useCache;
45
File cacheDirectory;
46
boolean cacheSettingsOK = false;
47
String threadName;
48
49
boolean gotCrosstalk = false;
50
51
public TestThread(ThreadGroup tg,
52
boolean useCache, File cacheDirectory,
53
String threadName) {
54
super(tg, threadName);
55
this.useCache = useCache;
56
this.cacheDirectory = cacheDirectory;
57
this.threadName = threadName;
58
}
59
60
public void run() {
61
// System.out.println("Thread " + threadName + " in thread group " +
62
// getThreadGroup().getName());
63
64
// Create a new AppContext as though we were an applet
65
SunToolkit.createNewAppContext();
66
67
// Get default registry and store reference
68
this.registry = IIORegistry.getDefaultInstance();
69
70
for (int i = 0; i < 10; i++) {
71
// System.out.println(threadName +
72
// ": setting cache parameters to " +
73
// useCache + ", " + cacheDirectory);
74
ImageIO.setUseCache(useCache);
75
ImageIO.setCacheDirectory(cacheDirectory);
76
77
try {
78
sleep(1000L);
79
} catch (InterruptedException e) {
80
}
81
82
// System.out.println(threadName + ": reading cache parameters");
83
boolean newUseCache = ImageIO.getUseCache();
84
File newCacheDirectory = ImageIO.getCacheDirectory();
85
if (newUseCache != useCache ||
86
newCacheDirectory != cacheDirectory) {
87
// System.out.println(threadName + ": got " +
88
// newUseCache + ", " +
89
// newCacheDirectory);
90
// System.out.println(threadName + ": crosstalk encountered!");
91
gotCrosstalk = true;
92
}
93
}
94
}
95
96
public IIORegistry getRegistry() {
97
return registry;
98
}
99
100
public boolean gotCrosstalk() {
101
return gotCrosstalk;
102
}
103
}
104
105
public class AppContextTest {
106
107
public AppContextTest() {
108
ThreadGroup tg0 = new ThreadGroup("ThreadGroup0");
109
ThreadGroup tg1 = new ThreadGroup("ThreadGroup1");
110
111
TestThread t0 =
112
new TestThread(tg0, false, null, "TestThread 0");
113
TestThread t1 =
114
new TestThread(tg1, true, new File("."), "TestThread 1");
115
116
t0.start();
117
t1.start();
118
119
try {
120
t0.join();
121
} catch (InterruptedException ie0) {
122
}
123
try {
124
t1.join();
125
} catch (InterruptedException ie1) {
126
}
127
128
if (t0.gotCrosstalk() || t1.gotCrosstalk()) {
129
throw new RuntimeException("ImageIO methods had crosstalk!");
130
}
131
132
if (t0.getRegistry() == t1.getRegistry()) {
133
throw new RuntimeException("ThreadGroups had same IIORegistry!");
134
}
135
}
136
137
public static void main(String[] args) throws IOException {
138
new AppContextTest();
139
}
140
}
141
142