JDK-8179950 : Custom system class loader using Enum.valueOf in its initialization triggers java.lang.InternalError
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 9
  • Priority: P1
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2017-05-09
  • Updated: 2017-05-12
  • Resolved: 2017-05-09
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 10 JDK 9
10Fixed 9 b169Fixed
Related Reports
Relates :  
Description
This seems to be a regression caused by JDK-8020801.

Here's the stack trace of WLS running on jdk9/dev with a custom system class loader:

Error occurred during initialization of VM

java.lang.Error: java.lang.reflect.InvocationTargetException

        at java.lang.ClassLoader.initSystemClassLoader(java.base@9-internal/ClassLoader.java:1952)

        at java.lang.System.initPhase3(java.base@9-internal/System.java:2048)

Caused by: java.lang.reflect.InvocationTargetException

        at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(java.base@9-internal/Native Method)

        at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(java.base@9-internal/NativeConstructorAccessorImpl.java:62)

        at jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(java.base@9-internal/DelegatingConstructorAccessorImpl.java:45)

        at java.lang.reflect.Constructor.newInstance(java.base@9-internal/Constructor.java:487)

        at java.lang.ClassLoader.initSystemClassLoader(java.base@9-internal/ClassLoader.java:1950)

        at java.lang.System.initPhase3(java.base@9-internal/System.java:2048)

Caused by: java.lang.InternalError: getSystemClassLoader should only be called after VM booted

        at java.lang.ClassLoader.getSystemClassLoader(java.base@9-internal/ClassLoader.java:1902)

        at jdk.internal.reflect.Reflection.isExtClassLoader(java.base@9-internal/Reflection.java:325)

        at jdk.internal.reflect.Reflection.isCallerSensitive(java.base@9-internal/Reflection.java:318)

        at jdk.internal.reflect.ReflectionFactory.newMethodAccessor(java.base@9-internal/ReflectionFactory.java:182)

        at java.lang.reflect.Method.acquireMethodAccessor(java.base@9-internal/Method.java:629)

        at java.lang.reflect.Method.invoke(java.base@9-internal/Method.java:561)

        at java.lang.Class.getEnumConstantsShared(java.base@9-internal/Class.java:3516)

        at java.lang.Class.enumConstantDirectory(java.base@9-internal/Class.java:3538)

        at java.lang.Enum.valueOf(java.base@9-internal/Enum.java:234)

        at com.oracle.classloader.weblogic.LaunchClassLoader$IndexType.valueOf(LaunchClassLoader.java:154)

        at com.oracle.classloader.weblogic.LaunchClassLoader.cacheFile(LaunchClassLoader.java:126)

        at com.oracle.classloader.weblogic.LaunchClassLoader.access$100(LaunchClassLoader.java:22)

        at com.oracle.classloader.weblogic.LaunchClassLoader$SystemLaunchConfiguration.<init>(LaunchClassLoader.java:73)

        at com.oracle.classloader.weblogic.LaunchClassLoader.<init>(LaunchClassLoader.java:37)

        at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(java.base@9-internal/Native Method)

        at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(java.base@9-internal/NativeConstructorAccessorImpl.java:62)

        at jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(java.base@9-internal/DelegatingConstructorAccessorImpl.java:45)

        at java.lang.reflect.Constructor.newInstance(java.base@9-internal/Constructor.java:487)

        at java.lang.ClassLoader.initSystemClassLoader(java.base@9-internal/ClassLoader.java:1950)

        at java.lang.System.initPhase3(java.base@9-internal/System.java:2048)
Comments
JDK 9 Fix Request It's a regression caused by JDK-8020801 that custom system loader may be broken by this. Must fix.
09-05-2017

diff --git a/src/java.base/share/classes/jdk/internal/reflect/Reflection.java b/src/java.base/share/classes/jdk/internal/reflect/Reflection.java --- a/src/java.base/share/classes/jdk/internal/reflect/Reflection.java +++ b/src/java.base/share/classes/jdk/internal/reflect/Reflection.java @@ -31,6 +31,7 @@ import java.util.Map; import java.util.Objects; import jdk.internal.HotSpotIntrinsicCandidate; +import jdk.internal.loader.ClassLoaders; import jdk.internal.misc.VM; /** Common utility routines used by both java.lang and @@ -315,23 +316,13 @@ */ public static boolean isCallerSensitive(Method m) { final ClassLoader loader = m.getDeclaringClass().getClassLoader(); - if (VM.isSystemDomainLoader(loader) || isExtClassLoader(loader)) { + if (VM.isSystemDomainLoader(loader) || + loader == ClassLoaders.platformClassLoader()) { return m.isAnnotationPresent(CallerSensitive.class); } return false; } - private static boolean isExtClassLoader(ClassLoader loader) {
09-05-2017

One way to fix this is to change Reflection.isExtClassLoader to test if the class loader === ClassLoaders.platformClassLoader().
09-05-2017