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/beans/Introspector/7064279/Test7064279.java
86410 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
/*
25
* @test
26
* @bug 7064279
27
* @summary Tests that Introspector does not have strong references to context class loader
28
* @author Sergey Malenkov
29
*/
30
31
import java.beans.Introspector;
32
import java.io.File;
33
import java.lang.ref.WeakReference;
34
import java.net.URL;
35
import java.net.URLClassLoader;
36
37
public class Test7064279 {
38
39
public static void main(String[] args) throws Exception {
40
WeakReference ref = new WeakReference(test("test.jar", "test.Test"));
41
try {
42
int[] array = new int[1024];
43
while (true) {
44
array = new int[array.length << 1];
45
}
46
}
47
catch (OutOfMemoryError error) {
48
System.gc();
49
}
50
if (null != ref.get()) {
51
throw new Error("ClassLoader is not released");
52
}
53
}
54
55
private static Object test(String jarName, String className) throws Exception {
56
StringBuilder sb = new StringBuilder(256);
57
sb.append("file:");
58
sb.append(System.getProperty("test.src", "."));
59
sb.append(File.separatorChar);
60
sb.append(jarName);
61
62
ClassLoader newLoader = new URLClassLoader(new URL[] { new URL(sb.toString()) });
63
ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
64
65
Thread.currentThread().setContextClassLoader(newLoader);
66
test(newLoader.loadClass(className));
67
Thread.currentThread().setContextClassLoader(oldLoader);
68
69
return newLoader;
70
}
71
72
private static void test(Class type) throws Exception {
73
Introspector.getBeanInfo(type);
74
}
75
}
76
77