|
|
a09adfd |
From e6cbfae1b59a4339275b88cfde8f7c3e22fdea75 Mon Sep 17 00:00:00 2001
|
|
|
a09adfd |
From: Ernestas Kulik <ekulik@redhat.com>
|
|
|
a09adfd |
Date: Wed, 10 Jun 2020 09:06:10 +0200
|
|
|
a09adfd |
Subject: [PATCH 6/8] =?UTF-8?q?test:=20RemoteTest:=20Don=E2=80=99t=20call?=
|
|
|
a09adfd |
=?UTF-8?q?=20URLClassLoader.addURL()?=
|
|
|
a09adfd |
MIME-Version: 1.0
|
|
|
a09adfd |
Content-Type: text/plain; charset=UTF-8
|
|
|
a09adfd |
Content-Transfer-Encoding: 8bit
|
|
|
a09adfd |
|
|
|
a09adfd |
It’s a protected method and some future version of Java will start
|
|
|
a09adfd |
restricting access via reflection, so let’s just use the legal way.
|
|
|
a09adfd |
---
|
|
|
a09adfd |
test/RemoteTest.java | 8 +++-----
|
|
|
a09adfd |
test/outputs/run_remote.log.in | 20 ++++++++++----------
|
|
|
a09adfd |
2 files changed, 13 insertions(+), 15 deletions(-)
|
|
|
a09adfd |
|
|
|
a09adfd |
diff --git a/test/RemoteTest.java b/test/RemoteTest.java
|
|
|
a09adfd |
index 040384f..e92e6f5 100644
|
|
|
a09adfd |
--- a/test/RemoteTest.java
|
|
|
a09adfd |
+++ b/test/RemoteTest.java
|
|
|
a09adfd |
@@ -83,19 +83,17 @@ public class RemoteTest {
|
|
|
a09adfd |
input.close();
|
|
|
a09adfd |
|
|
|
a09adfd |
try {
|
|
|
a09adfd |
- Method method = URLClassLoader.class.getDeclaredMethod("addURL", new Class[]{URL.class});
|
|
|
a09adfd |
- method.setAccessible(true);
|
|
|
a09adfd |
- method.invoke(ClassLoader.getSystemClassLoader(), new Object[]{remoteJarUrl});
|
|
|
a09adfd |
+ ClassLoader loader = URLClassLoader.newInstance(new URL[]{remoteJarUrl}, ClassLoader.getSystemClassLoader());
|
|
|
a09adfd |
/* Loaded these classes into cache. */
|
|
|
a09adfd |
final String needed[] = {"SimpleTest", "ThreadUncaughtException", "ThreadCaughtException"};
|
|
|
a09adfd |
for (String requiredClass : needed) {
|
|
|
a09adfd |
- if (null == Class.forName(requiredClass)) {
|
|
|
a09adfd |
+ if (null == Class.forName(requiredClass, true, loader)) {
|
|
|
a09adfd |
System.out.println("Cannot get required class: " + requiredClass);
|
|
|
a09adfd |
System.exit(1);
|
|
|
a09adfd |
}
|
|
|
a09adfd |
}
|
|
|
a09adfd |
|
|
|
a09adfd |
- testClassInstance = Class.forName(testClassName);
|
|
|
a09adfd |
+ testClassInstance = Class.forName(testClassName, true, loader);
|
|
|
a09adfd |
}
|
|
|
a09adfd |
finally {
|
|
|
a09adfd |
server.stop(0);
|
|
|
a09adfd |
diff --git a/test/outputs/run_remote.log.in b/test/outputs/run_remote.log.in
|
|
|
a09adfd |
index 31ef171..00bf701 100644
|
|
|
a09adfd |
--- a/test/outputs/run_remote.log.in
|
|
|
a09adfd |
+++ b/test/outputs/run_remote.log.in
|
|
|
a09adfd |
@@ -3,19 +3,19 @@ Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 42 ou
|
|
|
a09adfd |
at SimpleTest.throwIndexOutOfBoundsException(SimpleTest.java:24) [jar:http://localhost:54321/JarTest.jar!/SimpleTest.class]
|
|
|
a09adfd |
at SimpleTest.catchIndexOutOfBoundsException(SimpleTest.java:47) [jar:http://localhost:54321/JarTest.jar!/SimpleTest.class]
|
|
|
a09adfd |
at SimpleTest.throwAndCatchAllExceptions(SimpleTest.java:61) [jar:http://localhost:54321/JarTest.jar!/SimpleTest.class]
|
|
|
a09adfd |
- at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [jar:file:JAVA_AND_SYSTEM_SPECIFIC_PATH/rt.jar!/sun/reflect/NativeMethodAccessorImpl.class]
|
|
|
a09adfd |
- at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:LINENO) [jar:file:JAVA_AND_SYSTEM_SPECIFIC_PATH/rt.jar!/sun/reflect/NativeMethodAccessorImpl.class]
|
|
|
a09adfd |
- at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:LINENO) [jar:file:JAVA_AND_SYSTEM_SPECIFIC_PATH/rt.jar!/sun/reflect/DelegatingMethodAccessorImpl.class]
|
|
|
a09adfd |
- at java.lang.reflect.Method.invoke(Method.java:LINENO) [jar:file:JAVA_AND_SYSTEM_SPECIFIC_PATH/rt.jar!/java/lang/reflect/Method.class]
|
|
|
a09adfd |
- at RemoteTest.main(RemoteTest.java:110) [file:@CMAKE_BINARY_DIR@/test/RemoteTest.class]
|
|
|
a09adfd |
+ at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [jrt:/java.base/jdk/internal/reflect/NativeMethodAccessorImpl.class]
|
|
|
a09adfd |
+ at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:LINENO) [jrt:/java.base/jdk/internal/reflect/NativeMethodAccessorImpl.class]
|
|
|
a09adfd |
+ at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:LINENO) [jrt:/java.base/jdk/internal/reflect/DelegatingMethodAccessorImpl.class]
|
|
|
a09adfd |
+ at java.base/java.lang.reflect.Method.invoke(Method.java:LINENO) [jrt:/java.base/java/lang/reflect/Method.class]
|
|
|
a09adfd |
+ at RemoteTest.main(RemoteTest.java:108) [file:@CMAKE_BINARY_DIR@/test/RemoteTest.class]
|
|
|
a09adfd |
executable: @CMAKE_BINARY_DIR@/test/RemoteTest.class
|
|
|
a09adfd |
Uncaught exception java.lang.NullPointerException in method SimpleTest.throwNullPointerException()
|
|
|
a09adfd |
Exception in thread "main" java.lang.NullPointerException
|
|
|
a09adfd |
at SimpleTest.throwNullPointerException(SimpleTest.java:36) [jar:http://localhost:54321/JarTest.jar!/SimpleTest.class]
|
|
|
a09adfd |
at SimpleTest.throwAndDontCatchException(SimpleTest.java:71) [jar:http://localhost:54321/JarTest.jar!/SimpleTest.class]
|
|
|
a09adfd |
- at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [jar:file:JAVA_AND_SYSTEM_SPECIFIC_PATH/rt.jar!/sun/reflect/NativeMethodAccessorImpl.class]
|
|
|
a09adfd |
- at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:LINENO) [jar:file:JAVA_AND_SYSTEM_SPECIFIC_PATH/rt.jar!/sun/reflect/NativeMethodAccessorImpl.class]
|
|
|
a09adfd |
- at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:LINENO) [jar:file:JAVA_AND_SYSTEM_SPECIFIC_PATH/rt.jar!/sun/reflect/DelegatingMethodAccessorImpl.class]
|
|
|
a09adfd |
- at java.lang.reflect.Method.invoke(Method.java:LINENO) [jar:file:JAVA_AND_SYSTEM_SPECIFIC_PATH/rt.jar!/java/lang/reflect/Method.class]
|
|
|
a09adfd |
- at RemoteTest.main(RemoteTest.java:112) [file:@CMAKE_BINARY_DIR@/test/RemoteTest.class]
|
|
|
a09adfd |
+ at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [jrt:/java.base/jdk/internal/reflect/NativeMethodAccessorImpl.class]
|
|
|
a09adfd |
+ at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:LINENO) [jrt:/java.base/jdk/internal/reflect/NativeMethodAccessorImpl.class]
|
|
|
a09adfd |
+ at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:LINENO) [jrt:/java.base/jdk/internal/reflect/DelegatingMethodAccessorImpl.class]
|
|
|
a09adfd |
+ at java.base/java.lang.reflect.Method.invoke(Method.java:LINENO) [jrt:/java.base/java/lang/reflect/Method.class]
|
|
|
a09adfd |
+ at RemoteTest.main(RemoteTest.java:110) [file:@CMAKE_BINARY_DIR@/test/RemoteTest.class]
|
|
|
a09adfd |
executable: @CMAKE_BINARY_DIR@/test/RemoteTest.class
|
|
|
a09adfd |
--
|
|
|
a09adfd |
2.26.2
|
|
|
a09adfd |
|