From d28c5d67abee33527eb9cc640cbf2e238374ca06 Mon Sep 17 00:00:00 2001 From: Jason Feng Date: Mon, 9 Oct 2023 11:20:40 -0400 Subject: [PATCH] JDK 8/11 OPENJDK_METHODHANDLES requires AccessController.doPrivileged() Wrapped ClassLoader.loadClass(className, false) with AccessController.doPrivileged(). Signed-off-by: Jason Feng --- .../share/classes/java/lang/ClassLoader.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/jcl/src/java.base/share/classes/java/lang/ClassLoader.java b/jcl/src/java.base/share/classes/java/lang/ClassLoader.java index 7e3f7791305..bf34db99bb8 100644 --- a/jcl/src/java.base/share/classes/java/lang/ClassLoader.java +++ b/jcl/src/java.base/share/classes/java/lang/ClassLoader.java @@ -1239,7 +1239,22 @@ public Class loadClass(String className) throws ClassNotFoundException { throw new ClassNotFoundException(className); } /*[ENDIF] JAVA_SPEC_VERSION > 8 */ + +/*[IF OPENJDK_METHODHANDLES & (JAVA_SPEC_VERSION <= 11)]*/ + try { + return java.security.AccessController.doPrivileged((java.security.PrivilegedExceptionAction>) () -> { + return loadClass(className, false); + }); + } catch (java.security.PrivilegedActionException e) { + Throwable t = e.getCause(); + if (t instanceof ClassNotFoundException) { + throw (ClassNotFoundException)t; + } + throw new InternalError(t); + } +/*[ELSE] OPENJDK_METHODHANDLES & (JAVA_SPEC_VERSION <= 11)*/ return loadClass(className, false); +/*[ENDIF] OPENJDK_METHODHANDLES & (JAVA_SPEC_VERSION <= 11)*/ } /**