diff options
author | Mathieu Chartier <mathieuc@google.com> | 2015-03-30 01:57:02 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2015-03-30 01:57:02 +0000 |
commit | a3d40d5f764adfde8fa40d826cd93ba36cd15437 (patch) | |
tree | c83ae300ed8429c10fec05f53137b911cff41b43 /runtime | |
parent | af38d89634edbef394b3ef2cb3390d08dfb8d939 (diff) | |
parent | ca239af73e512df5eeb80fe6c09c2ca614649e06 (diff) | |
download | android_art-a3d40d5f764adfde8fa40d826cd93ba36cd15437.tar.gz android_art-a3d40d5f764adfde8fa40d826cd93ba36cd15437.tar.bz2 android_art-a3d40d5f764adfde8fa40d826cd93ba36cd15437.zip |
Merge "Fix some reflection errors"
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/native/java_lang_Class.cc | 5 | ||||
-rw-r--r-- | runtime/native/java_lang_reflect_Field.cc | 6 | ||||
-rw-r--r-- | runtime/reflection.cc | 6 | ||||
-rw-r--r-- | runtime/reflection.h | 2 |
4 files changed, 11 insertions, 8 deletions
diff --git a/runtime/native/java_lang_Class.cc b/runtime/native/java_lang_Class.cc index 3cb6b367f0..0ca9d24824 100644 --- a/runtime/native/java_lang_Class.cc +++ b/runtime/native/java_lang_Class.cc @@ -253,7 +253,10 @@ static jobject Class_getDeclaredField(JNIEnv* env, jobject javaThis, jstring nam mirror::Field* result = GetDeclaredField(soa.Self(), klass, name_string); if (result == nullptr) { std::string name_str = name_string->ToModifiedUtf8(); - soa.Self()->ThrowNewException("Ljava/lang/NoSuchFieldException;", name_str.c_str()); + // We may have a pending exception if we failed to resolve. + if (!soa.Self()->IsExceptionPending()) { + soa.Self()->ThrowNewException("Ljava/lang/NoSuchFieldException;", name_str.c_str()); + } return nullptr; } return soa.AddLocalReference<jobject>(result); diff --git a/runtime/native/java_lang_reflect_Field.cc b/runtime/native/java_lang_reflect_Field.cc index 0fe78b3281..721b7a3b76 100644 --- a/runtime/native/java_lang_reflect_Field.cc +++ b/runtime/native/java_lang_reflect_Field.cc @@ -44,7 +44,7 @@ ALWAYS_INLINE inline static bool VerifyFieldAccess(Thread* self, mirror::Field* } mirror::Class* calling_class = nullptr; if (!VerifyAccess(self, obj, field->GetDeclaringClass(), field->GetAccessFlags(), - &calling_class)) { + &calling_class, 1)) { ThrowIllegalAccessException( StringPrintf("Class %s cannot access %s field %s of class %s", calling_class == nullptr ? "null" : PrettyClass(calling_class).c_str(), @@ -276,9 +276,9 @@ ALWAYS_INLINE inline static void SetFieldValue(mirror::Object* o, mirror::Field* break; case Primitive::kPrimShort: if (is_volatile) { - o->SetFieldShortVolatile<false>(offset, new_value.GetZ()); + o->SetFieldShortVolatile<false>(offset, new_value.GetS()); } else { - o->SetFieldShort<false>(offset, new_value.GetZ()); + o->SetFieldShort<false>(offset, new_value.GetS()); } break; case Primitive::kPrimNot: diff --git a/runtime/reflection.cc b/runtime/reflection.cc index d845e402e7..4e94de4139 100644 --- a/runtime/reflection.cc +++ b/runtime/reflection.cc @@ -587,7 +587,7 @@ jobject InvokeMethod(const ScopedObjectAccessAlreadyRunnable& soa, jobject javaM // If method is not set to be accessible, verify it can be accessed by the caller. mirror::Class* calling_class = nullptr; if (!accessible && !VerifyAccess(soa.Self(), receiver, declaring_class, m->GetAccessFlags(), - &calling_class)) { + &calling_class, 2)) { ThrowIllegalAccessException( StringPrintf("Class %s cannot access %s method %s of class %s", calling_class == nullptr ? "null" : PrettyClass(calling_class).c_str(), @@ -794,11 +794,11 @@ bool UnboxPrimitiveForResult(mirror::Object* o, } bool VerifyAccess(Thread* self, mirror::Object* obj, mirror::Class* declaring_class, - uint32_t access_flags, mirror::Class** calling_class) { + uint32_t access_flags, mirror::Class** calling_class, size_t num_frames) { if ((access_flags & kAccPublic) != 0) { return true; } - NthCallerVisitor visitor(self, 2); + NthCallerVisitor visitor(self, num_frames); visitor.WalkStack(); if (UNLIKELY(visitor.caller == nullptr)) { // The caller is an attached native thread. diff --git a/runtime/reflection.h b/runtime/reflection.h index 6bef664ca4..ff970e5507 100644 --- a/runtime/reflection.h +++ b/runtime/reflection.h @@ -73,7 +73,7 @@ ALWAYS_INLINE bool VerifyObjectIsClass(mirror::Object* o, mirror::Class* c) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); bool VerifyAccess(Thread* self, mirror::Object* obj, mirror::Class* declaring_class, - uint32_t access_flags, mirror::Class** calling_class) + uint32_t access_flags, mirror::Class** calling_class, size_t num_frames) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); void InvalidReceiverError(mirror::Object* o, mirror::Class* c) |