This repository was archived by the owner on Oct 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathBootstrapLoaderTest.java
96 lines (86 loc) · 2.85 KB
/
BootstrapLoaderTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package wtf.java9.class_loading;
import org.junit.jupiter.api.TestReporter;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import java.util.stream.Stream;
import static org.assertj.core.api.Assertions.assertThat;
/**
* A simple utility class that validates some of the key java.* and javax.* package class visibility
* from the bootstrap ClassLoader
*/
public class BootstrapLoaderTest {
@ParameterizedTest(name = "loading {0}")
@MethodSource(value = "classNames")
public void loadJdkClass(String className, TestReporter reporter) throws ClassNotFoundException {
TestClassLoader classLoader = new TestClassLoader();
try {
Class c = classLoader.loadClass(className);
reporter.publishEntry(className, "visible");
// the assertion is pretty useless, but if `c` would not be used,
// dead code elimination might remove it
assertThat(c.getName()).isEqualTo(className);
} catch (ClassNotFoundException ex) {
reporter.publishEntry(className, "not visible");
throw ex;
}
}
private static Stream<String> classNames() {
return Stream.of(
"java.applet.Applet",
"java.awt.Image",
"java.awt.dnd.DropTarget",
"java.awt.print.Paper",
"java.beans.BeanInfo",
"java.lang.instrument.ClassFileTransformer",
"java.lang.management.ClassLoadingMXBean",
"java.sql.Date",
"java.net.ServerSocket",
"java.rmi.Naming",
"java.rmi.activation.Activator",
"java.security.acl.Acl",
"java.text.spi.NumberFormatProvider",
"java.util.logging.Logger",
"java.util.prefs.Preferences",
"java.util.zip.ZipFile",
"javax.activation.DataHandler",
"javax.annotation.PostConstruct",
"javax.imageio.ImageIO",
"javax.jws.WebMethod",
"javax.lang.model.SourceVersion",
"javax.management.JMX",
"javax.naming.Context",
"javax.net.SocketFactory",
"javax.print.PrintService",
"javax.rmi.PortableRemoteObject",
"javax.script.AbstractScriptEngine",
"javax.security.cert.X509Certificate",
"javax.smartcardio.Card",
"javax.sound.midi.MidiDevice",
"javax.sql.XADataSource",
"javax.swing.SwingUtilities",
"javax.tools.JavaCompiler",
"javax.transaction.xa.XAResource",
"javax.xml.XMLConstants",
"javax.xml.bind.Element",
"javax.xml.bind.annotation.XmlElement",
"javax.xml.crypto.XMLStructure",
"javax.xml.datatype.DatatypeConstants",
"javax.xml.namespace.QName",
"javax.xml.parsers.DocumentBuilder",
"javax.xml.soap.Name",
"javax.xml.stream.XMLStreamConstants",
"javax.xml.transform.Transformer",
"javax.xml.validation.Validator",
"javax.xml.ws.Service",
"javax.xml.xpath.XPath"
);
}
/**
* A simple ClassLoader that specifies null to use the bootstrap ClassLoader as its parent
*/
static class TestClassLoader extends ClassLoader {
TestClassLoader() {
super(null);
}
}
}