8057919: Class.getSimpleName() should work for non-JLS compliant class names
Reviewed-by: dholmes, jrose
This commit is contained in:
parent
af1efee490
commit
ce40bf07b2
hotspot
make
aix/makefiles
bsd/makefiles
linux/makefiles
solaris/makefiles
src/share/vm
@ -19,7 +19,7 @@
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
#
|
||||
#
|
||||
|
||||
# Define public interface.
|
||||
@ -107,6 +107,7 @@ SUNWprivate_1.1 {
|
||||
JVM_GetClassTypeAnnotations;
|
||||
JVM_GetDeclaredClasses;
|
||||
JVM_GetDeclaringClass;
|
||||
JVM_GetSimpleBinaryName;
|
||||
JVM_GetEnclosingMethodInfo;
|
||||
JVM_GetFieldIxModifiers;
|
||||
JVM_GetFieldTypeAnnotations;
|
||||
|
@ -19,7 +19,7 @@
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
#
|
||||
#
|
||||
|
||||
# Define public interface.
|
||||
@ -107,6 +107,7 @@ SUNWprivate_1.1 {
|
||||
JVM_GetClassTypeAnnotations;
|
||||
JVM_GetDeclaredClasses;
|
||||
JVM_GetDeclaringClass;
|
||||
JVM_GetSimpleBinaryName;
|
||||
JVM_GetEnclosingMethodInfo;
|
||||
JVM_GetFieldIxModifiers;
|
||||
JVM_GetInheritedAccessControlContext;
|
||||
|
@ -105,6 +105,7 @@
|
||||
_JVM_GetClassTypeAnnotations
|
||||
_JVM_GetDeclaredClasses
|
||||
_JVM_GetDeclaringClass
|
||||
_JVM_GetSimpleBinaryName
|
||||
_JVM_GetEnclosingMethodInfo
|
||||
_JVM_GetFieldIxModifiers
|
||||
_JVM_GetFieldTypeAnnotations
|
||||
|
@ -105,6 +105,7 @@
|
||||
_JVM_GetClassTypeAnnotations
|
||||
_JVM_GetDeclaredClasses
|
||||
_JVM_GetDeclaringClass
|
||||
_JVM_GetSimpleBinaryName
|
||||
_JVM_GetEnclosingMethodInfo
|
||||
_JVM_GetFieldIxModifiers
|
||||
_JVM_GetFieldTypeAnnotations
|
||||
|
@ -19,7 +19,7 @@
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
#
|
||||
#
|
||||
|
||||
# Define public interface.
|
||||
@ -107,6 +107,7 @@ SUNWprivate_1.1 {
|
||||
JVM_GetClassTypeAnnotations;
|
||||
JVM_GetDeclaredClasses;
|
||||
JVM_GetDeclaringClass;
|
||||
JVM_GetSimpleBinaryName;
|
||||
JVM_GetEnclosingMethodInfo;
|
||||
JVM_GetFieldIxModifiers;
|
||||
JVM_GetFieldTypeAnnotations;
|
||||
|
@ -19,7 +19,7 @@
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
#
|
||||
#
|
||||
|
||||
# Define public interface.
|
||||
@ -107,6 +107,7 @@ SUNWprivate_1.1 {
|
||||
JVM_GetClassTypeAnnotations;
|
||||
JVM_GetDeclaredClasses;
|
||||
JVM_GetDeclaringClass;
|
||||
JVM_GetSimpleBinaryName;
|
||||
JVM_GetEnclosingMethodInfo;
|
||||
JVM_GetFieldIxModifiers;
|
||||
JVM_GetFieldTypeAnnotations;
|
||||
|
@ -19,7 +19,7 @@
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
#
|
||||
#
|
||||
|
||||
# Define public interface.
|
||||
@ -107,6 +107,7 @@ SUNWprivate_1.1 {
|
||||
JVM_GetClassTypeAnnotations;
|
||||
JVM_GetDeclaredClasses;
|
||||
JVM_GetDeclaringClass;
|
||||
JVM_GetSimpleBinaryName;
|
||||
JVM_GetEnclosingMethodInfo;
|
||||
JVM_GetFieldIxModifiers;
|
||||
JVM_GetFieldTypeAnnotations;
|
||||
|
@ -19,7 +19,7 @@
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
#
|
||||
#
|
||||
|
||||
# Define public interface.
|
||||
@ -107,6 +107,7 @@ SUNWprivate_1.1 {
|
||||
JVM_GetClassTypeAnnotations;
|
||||
JVM_GetDeclaredClasses;
|
||||
JVM_GetDeclaringClass;
|
||||
JVM_GetSimpleBinaryName;
|
||||
JVM_GetEnclosingMethodInfo;
|
||||
JVM_GetFieldIxModifiers;
|
||||
JVM_GetFieldTypeAnnotations;
|
||||
|
@ -19,7 +19,7 @@
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
#
|
||||
#
|
||||
|
||||
# Define public interface.
|
||||
@ -30,7 +30,7 @@ SUNWprivate_1.1 {
|
||||
JNI_CreateJavaVM;
|
||||
JNI_GetCreatedJavaVMs;
|
||||
JNI_GetDefaultJavaVMInitArgs;
|
||||
|
||||
|
||||
# JVM
|
||||
JVM_ActiveProcessorCount;
|
||||
JVM_ArrayCopy;
|
||||
@ -107,6 +107,7 @@ SUNWprivate_1.1 {
|
||||
JVM_GetClassTypeAnnotations;
|
||||
JVM_GetDeclaredClasses;
|
||||
JVM_GetDeclaringClass;
|
||||
JVM_GetSimpleBinaryName;
|
||||
JVM_GetEnclosingMethodInfo;
|
||||
JVM_GetFieldIxModifiers;
|
||||
JVM_GetFieldTypeAnnotations;
|
||||
|
@ -2712,6 +2712,57 @@ bool InstanceKlass::is_same_package_member_impl(instanceKlassHandle class1,
|
||||
return false;
|
||||
}
|
||||
|
||||
bool InstanceKlass::find_inner_classes_attr(instanceKlassHandle k, int* ooff, int* noff, TRAPS) {
|
||||
constantPoolHandle i_cp(THREAD, k->constants());
|
||||
for (InnerClassesIterator iter(k); !iter.done(); iter.next()) {
|
||||
int ioff = iter.inner_class_info_index();
|
||||
if (ioff != 0) {
|
||||
// Check to see if the name matches the class we're looking for
|
||||
// before attempting to find the class.
|
||||
if (i_cp->klass_name_at_matches(k, ioff)) {
|
||||
Klass* inner_klass = i_cp->klass_at(ioff, CHECK_false);
|
||||
if (k() == inner_klass) {
|
||||
*ooff = iter.outer_class_info_index();
|
||||
*noff = iter.inner_name_index();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Klass* InstanceKlass::compute_enclosing_class_impl(instanceKlassHandle k, bool* inner_is_member, TRAPS) {
|
||||
instanceKlassHandle outer_klass;
|
||||
*inner_is_member = false;
|
||||
int ooff = 0, noff = 0;
|
||||
if (find_inner_classes_attr(k, &ooff, &noff, THREAD)) {
|
||||
constantPoolHandle i_cp(THREAD, k->constants());
|
||||
if (ooff != 0) {
|
||||
Klass* ok = i_cp->klass_at(ooff, CHECK_NULL);
|
||||
outer_klass = instanceKlassHandle(THREAD, ok);
|
||||
*inner_is_member = true;
|
||||
}
|
||||
if (outer_klass.is_null()) {
|
||||
// It may be anonymous; try for that.
|
||||
int encl_method_class_idx = k->enclosing_method_class_index();
|
||||
if (encl_method_class_idx != 0) {
|
||||
Klass* ok = i_cp->klass_at(encl_method_class_idx, CHECK_NULL);
|
||||
outer_klass = instanceKlassHandle(THREAD, ok);
|
||||
*inner_is_member = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If no inner class attribute found for this class.
|
||||
if (outer_klass.is_null()) return NULL;
|
||||
|
||||
// Throws an exception if outer klass has not declared k as an inner klass
|
||||
// We need evidence that each klass knows about the other, or else
|
||||
// the system could allow a spoof of an inner class to gain access rights.
|
||||
Reflection::check_for_inner_class(outer_klass, k, *inner_is_member, CHECK_NULL);
|
||||
return outer_klass();
|
||||
}
|
||||
|
||||
jint InstanceKlass::compute_modifier_flags(TRAPS) const {
|
||||
jint access = access_flags().as_int();
|
||||
|
@ -404,13 +404,17 @@ class InstanceKlass: public Klass {
|
||||
bool is_same_class_package(oop classloader2, Symbol* classname2);
|
||||
static bool is_same_class_package(oop class_loader1, Symbol* class_name1, oop class_loader2, Symbol* class_name2);
|
||||
|
||||
// find an enclosing class (defined where original code was, in jvm.cpp!)
|
||||
// find an enclosing class
|
||||
Klass* compute_enclosing_class(bool* inner_is_member, TRAPS) {
|
||||
instanceKlassHandle self(THREAD, this);
|
||||
return compute_enclosing_class_impl(self, inner_is_member, THREAD);
|
||||
}
|
||||
static Klass* compute_enclosing_class_impl(instanceKlassHandle self,
|
||||
bool* inner_is_member, TRAPS);
|
||||
bool* inner_is_member, TRAPS);
|
||||
|
||||
// Find InnerClasses attribute for k and return outer_class_info_index & inner_name_index.
|
||||
static bool find_inner_classes_attr(instanceKlassHandle k,
|
||||
int* ooff, int* noff, TRAPS);
|
||||
|
||||
// tell if two classes have the same enclosing class (at package level)
|
||||
bool is_same_package_member(Klass* class2, TRAPS) {
|
||||
|
@ -1465,63 +1465,26 @@ JVM_ENTRY(jclass, JVM_GetDeclaringClass(JNIEnv *env, jclass ofClass))
|
||||
}
|
||||
JVM_END
|
||||
|
||||
// should be in InstanceKlass.cpp, but is here for historical reasons
|
||||
Klass* InstanceKlass::compute_enclosing_class_impl(instanceKlassHandle k,
|
||||
bool* inner_is_member,
|
||||
TRAPS) {
|
||||
Thread* thread = THREAD;
|
||||
InnerClassesIterator iter(k);
|
||||
if (iter.length() == 0) {
|
||||
// No inner class info => no declaring class
|
||||
JVM_ENTRY(jstring, JVM_GetSimpleBinaryName(JNIEnv *env, jclass cls))
|
||||
{
|
||||
oop mirror = JNIHandles::resolve_non_null(cls);
|
||||
if (java_lang_Class::is_primitive(mirror) ||
|
||||
!java_lang_Class::as_Klass(mirror)->oop_is_instance()) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
constantPoolHandle i_cp(thread, k->constants());
|
||||
|
||||
bool found = false;
|
||||
Klass* ok;
|
||||
instanceKlassHandle outer_klass;
|
||||
*inner_is_member = false;
|
||||
|
||||
// Find inner_klass attribute
|
||||
for (; !iter.done() && !found; iter.next()) {
|
||||
int ioff = iter.inner_class_info_index();
|
||||
int ooff = iter.outer_class_info_index();
|
||||
int noff = iter.inner_name_index();
|
||||
if (ioff != 0) {
|
||||
// Check to see if the name matches the class we're looking for
|
||||
// before attempting to find the class.
|
||||
if (i_cp->klass_name_at_matches(k, ioff)) {
|
||||
Klass* inner_klass = i_cp->klass_at(ioff, CHECK_NULL);
|
||||
found = (k() == inner_klass);
|
||||
if (found && ooff != 0) {
|
||||
ok = i_cp->klass_at(ooff, CHECK_NULL);
|
||||
outer_klass = instanceKlassHandle(thread, ok);
|
||||
*inner_is_member = true;
|
||||
}
|
||||
}
|
||||
instanceKlassHandle k(THREAD, InstanceKlass::cast(java_lang_Class::as_Klass(mirror)));
|
||||
int ooff = 0, noff = 0;
|
||||
if (InstanceKlass::find_inner_classes_attr(k, &ooff, &noff, THREAD)) {
|
||||
if (noff != 0) {
|
||||
constantPoolHandle i_cp(thread, k->constants());
|
||||
Symbol* name = i_cp->symbol_at(noff);
|
||||
Handle str = java_lang_String::create_from_symbol(name, CHECK_NULL);
|
||||
return (jstring) JNIHandles::make_local(env, str());
|
||||
}
|
||||
}
|
||||
|
||||
if (found && outer_klass.is_null()) {
|
||||
// It may be anonymous; try for that.
|
||||
int encl_method_class_idx = k->enclosing_method_class_index();
|
||||
if (encl_method_class_idx != 0) {
|
||||
ok = i_cp->klass_at(encl_method_class_idx, CHECK_NULL);
|
||||
outer_klass = instanceKlassHandle(thread, ok);
|
||||
*inner_is_member = false;
|
||||
}
|
||||
}
|
||||
|
||||
// If no inner class attribute found for this class.
|
||||
if (outer_klass.is_null()) return NULL;
|
||||
|
||||
// Throws an exception if outer klass has not declared k as an inner klass
|
||||
// We need evidence that each klass knows about the other, or else
|
||||
// the system could allow a spoof of an inner class to gain access rights.
|
||||
Reflection::check_for_inner_class(outer_klass, k, *inner_is_member, CHECK_NULL);
|
||||
return outer_klass();
|
||||
return NULL;
|
||||
}
|
||||
JVM_END
|
||||
|
||||
JVM_ENTRY(jstring, JVM_GetClassSignature(JNIEnv *env, jclass cls))
|
||||
assert (cls != NULL, "illegal class");
|
||||
|
@ -426,6 +426,9 @@ JVM_GetDeclaredClasses(JNIEnv *env, jclass ofClass);
|
||||
JNIEXPORT jclass JNICALL
|
||||
JVM_GetDeclaringClass(JNIEnv *env, jclass ofClass);
|
||||
|
||||
JNIEXPORT jstring JNICALL
|
||||
JVM_GetSimpleBinaryName(JNIEnv *env, jclass ofClass);
|
||||
|
||||
/* Generics support (JDK 1.5) */
|
||||
JNIEXPORT jstring JNICALL
|
||||
JVM_GetClassSignature(JNIEnv *env, jclass cls);
|
||||
|
Loading…
x
Reference in New Issue
Block a user