-
CSR
-
Resolution: Approved
-
P4
-
None
-
behavioral
-
minimal
-
-
Java API
-
SE
Summary
Specify Class::forName(String)
to use the system class loader if invoked with no caller frame.
Problem
The Class::forName(String)
method is a caller sensitive method but does not specify what should happen when there are no stack frames to determine the caller. Currently the boot loader is used when there is no caller.
JNI FindClass uses the system class loader instead if invoked via JNI invocation interface when there is no associated class loader. Class::forName
when invoked by JNI code with no caller frame should be consistent with JNI FindClass and use the system class loader if caller is null.
Solution
When there is no caller frame on the stack, simply use the system class loader.
Specification
The spec of java.lang.Class.forName(String) is updated as follows:
@@ -357,6 +357,11 @@ public final class Class<T> implements java.io.Serializable,
* A call to {@code forName("X")} causes the class named
* {@code X} to be initialized.
*
+ * <p>
+ * In cases where this method is called from a context where there is no
+ * caller frame on the stack (e.g. when called directly from a JNI
+ * attached thread), the system class loader is used.
+ *
* @param className the fully qualified name of the desired class.
* @return the {@code Class} object for the class with the
* specified name.
- csr of
-
JDK-8281001 Class::forName(String) defaults to system class loader if the caller is null
-
- Resolved
-