mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-23 04:24:49 +02:00
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
Put anonymous classes in unnamed package into host class's package. Throw exception if host class's package differs from anonymous class. Reviewed-by: coleenp, acorn
This commit is contained in:
parent
c271d83599
commit
e8e6415b7a
14 changed files with 416 additions and 31 deletions
|
@ -783,6 +783,7 @@ UNSAFE_ENTRY(jclass, Unsafe_DefineClass0(JNIEnv *env, jobject unsafe, jstring na
|
|||
|
||||
// define a class but do not make it known to the class loader or system dictionary
|
||||
// - host_class: supplies context for linkage, access control, protection domain, and class loader
|
||||
// if host_class is itself anonymous then it is replaced with its host class.
|
||||
// - data: bytes of a class file, a raw memory address (length gives the number of bytes)
|
||||
// - cp_patches: where non-null entries exist, they replace corresponding CP entries in data
|
||||
|
||||
|
@ -791,8 +792,12 @@ UNSAFE_ENTRY(jclass, Unsafe_DefineClass0(JNIEnv *env, jobject unsafe, jstring na
|
|||
// link to any member of U. Just after U is loaded, the only way to use it is reflectively,
|
||||
// through java.lang.Class methods like Class.newInstance.
|
||||
|
||||
// The package of an anonymous class must either match its host's class's package or be in the
|
||||
// unnamed package. If it is in the unnamed package then it will be put in its host class's
|
||||
// package.
|
||||
//
|
||||
|
||||
// Access checks for linkage sites within U continue to follow the same rules as for named classes.
|
||||
// The package of an anonymous class is given by the package qualifier on the name under which it was loaded.
|
||||
// An anonymous class also has special privileges to access any member of its host class.
|
||||
// This is the main reason why this loading operation is unsafe. The purpose of this is to
|
||||
// allow language implementations to simulate "open classes"; a host class in effect gets
|
||||
|
@ -874,9 +879,11 @@ Unsafe_DefineAnonymousClass_impl(JNIEnv *env,
|
|||
|
||||
// Primitive types have NULL Klass* fields in their java.lang.Class instances.
|
||||
if (host_klass == NULL) {
|
||||
THROW_0(vmSymbols::java_lang_IllegalArgumentException());
|
||||
THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Host class is null");
|
||||
}
|
||||
|
||||
assert(host_klass->is_instance_klass(), "Host class must be an instance class");
|
||||
|
||||
const char* host_source = host_klass->external_name();
|
||||
Handle host_loader(THREAD, host_klass->class_loader());
|
||||
Handle host_domain(THREAD, host_klass->protection_domain());
|
||||
|
@ -907,7 +914,7 @@ Unsafe_DefineAnonymousClass_impl(JNIEnv *env,
|
|||
host_loader,
|
||||
host_domain,
|
||||
&st,
|
||||
host_klass,
|
||||
InstanceKlass::cast(host_klass),
|
||||
cp_patches,
|
||||
CHECK_NULL);
|
||||
if (anonk == NULL) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue