74 @Test
75 public void runTest() throws Exception {
76 int exitValue = executeTestJava("--module-path", MODS_DIR.toString(),
77 "-m", "test/jdk.test.ProxyClassAccess")
78 .outputTo(System.out)
79 .errorTo(System.out)
80 .getExitValue();
81
82 assertTrue(exitValue == 0);
83 }
84
85 /**
86 * Test unnamed module has no access to other proxy interface
87 */
88 @Test
89 public void testNoReadAccess() throws Exception {
90 ModuleFinder finder = ModuleFinder.of(MODS_DIR);
91 Layer bootLayer = Layer.boot();
92 Configuration cf = bootLayer
93 .configuration()
94 .resolveRequiresAndUses(ModuleFinder.of(), finder, modules);
95 ClassLoader parentLoader = this.getClass().getClassLoader();
96 Layer layer = bootLayer.defineModulesWithOneLoader(cf, parentLoader);
97
98 ClassLoader loader = layer.findLoader("m1");
99 Class<?>[] interfaces = new Class<?>[] {
100 Class.forName("p.one.I", false, loader),
101 Class.forName("q.NP", false, loader) // non-public interface in unnamed module
102 };
103 checkIAE(loader, interfaces);
104 }
105
106 private void checkIAE(ClassLoader loader, Class<?>[] interfaces) {
107 try {
108 Proxy.getProxyClass(loader, interfaces);
109 throw new RuntimeException("Expected IllegalArgumentException thrown");
110 } catch (IllegalArgumentException e) {}
111
112 try {
113 Proxy.newProxyInstance(loader, interfaces,
114 (proxy, m, params) -> { throw new RuntimeException(m.toString()); });
|
74 @Test
75 public void runTest() throws Exception {
76 int exitValue = executeTestJava("--module-path", MODS_DIR.toString(),
77 "-m", "test/jdk.test.ProxyClassAccess")
78 .outputTo(System.out)
79 .errorTo(System.out)
80 .getExitValue();
81
82 assertTrue(exitValue == 0);
83 }
84
85 /**
86 * Test unnamed module has no access to other proxy interface
87 */
88 @Test
89 public void testNoReadAccess() throws Exception {
90 ModuleFinder finder = ModuleFinder.of(MODS_DIR);
91 Layer bootLayer = Layer.boot();
92 Configuration cf = bootLayer
93 .configuration()
94 .resolveAndBind(ModuleFinder.of(), finder, modules);
95 ClassLoader parentLoader = this.getClass().getClassLoader();
96 Layer layer = bootLayer.defineModulesWithOneLoader(cf, parentLoader);
97
98 ClassLoader loader = layer.findLoader("m1");
99 Class<?>[] interfaces = new Class<?>[] {
100 Class.forName("p.one.I", false, loader),
101 Class.forName("q.NP", false, loader) // non-public interface in unnamed module
102 };
103 checkIAE(loader, interfaces);
104 }
105
106 private void checkIAE(ClassLoader loader, Class<?>[] interfaces) {
107 try {
108 Proxy.getProxyClass(loader, interfaces);
109 throw new RuntimeException("Expected IllegalArgumentException thrown");
110 } catch (IllegalArgumentException e) {}
111
112 try {
113 Proxy.newProxyInstance(loader, interfaces,
114 (proxy, m, params) -> { throw new RuntimeException(m.toString()); });
|