Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/beans/Introspector/7064279/Test7064279.java
41153 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
* @run main/othervm -Xmx128m Test7064279
30
*/
31
32
import java.beans.Introspector;
33
import java.io.File;
34
import java.lang.ref.WeakReference;
35
import java.net.URL;
36
import java.net.URLClassLoader;
37
38
public class Test7064279 {
39
40
public static void main(String[] args) throws Exception {
41
WeakReference ref = new WeakReference(test("test.jar", "test.Test"));
42
try {
43
int[] array = new int[1024];
44
while (true) {
45
array = new int[array.length << 1];
46
}
47
}
48
catch (OutOfMemoryError error) {
49
System.gc();
50
}
51
if (null != ref.get()) {
52
throw new Error("ClassLoader is not released");
53
}
54
}
55
56
private static Object test(String jarName, String className) throws Exception {
57
StringBuilder sb = new StringBuilder(256);
58
sb.append("file:");
59
sb.append(System.getProperty("test.src", "."));
60
sb.append(File.separatorChar);
61
sb.append(jarName);
62
63
ClassLoader newLoader = new URLClassLoader(new URL[] { new URL(sb.toString()) });
64
ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
65
66
Thread.currentThread().setContextClassLoader(newLoader);
67
test(newLoader.loadClass(className));
68
Thread.currentThread().setContextClassLoader(oldLoader);
69
70
return newLoader;
71
}
72
73
private static void test(Class type) throws Exception {
74
Introspector.getBeanInfo(type);
75
}
76
}
77
78