mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8281001: Class::forName(String) defaults to system class loader if the caller is null
Reviewed-by: mchung
This commit is contained in:
parent
c68419f2f7
commit
b92ce2699b
4 changed files with 12 additions and 7 deletions
|
@ -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.
|
||||
|
@ -380,7 +385,9 @@ public final class Class<T> implements java.io.Serializable,
|
|||
@CallerSensitiveAdapter
|
||||
private static Class<?> forName(String className, Class<?> caller)
|
||||
throws ClassNotFoundException {
|
||||
return forName0(className, true, ClassLoader.getClassLoader(caller), caller);
|
||||
ClassLoader loader = (caller == null) ? ClassLoader.getSystemClassLoader()
|
||||
: ClassLoader.getClassLoader(caller);
|
||||
return forName0(className, true, loader, caller);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue