summaryrefslogtreecommitdiff
path: root/runtime/reflection.cc
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/reflection.cc')
-rw-r--r--runtime/reflection.cc30
1 files changed, 11 insertions, 19 deletions
diff --git a/runtime/reflection.cc b/runtime/reflection.cc
index a54a39d5d6..4e94de4139 100644
--- a/runtime/reflection.cc
+++ b/runtime/reflection.cc
@@ -24,7 +24,6 @@
#include "mirror/art_field-inl.h"
#include "mirror/art_method-inl.h"
#include "mirror/class-inl.h"
-#include "mirror/class.h"
#include "mirror/object_array-inl.h"
#include "mirror/object_array.h"
#include "nth_caller_visitor.h"
@@ -588,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(),
@@ -628,21 +627,6 @@ jobject InvokeMethod(const ScopedObjectAccessAlreadyRunnable& soa, jobject javaM
return soa.AddLocalReference<jobject>(BoxPrimitive(Primitive::GetType(shorty[0]), result));
}
-bool VerifyObjectIsClass(mirror::Object* o, mirror::Class* c) {
- if (o == nullptr) {
- ThrowNullPointerException("null receiver");
- return false;
- } else if (!o->InstanceOf(c)) {
- std::string expected_class_name(PrettyDescriptor(c));
- std::string actual_class_name(PrettyTypeOf(o));
- ThrowIllegalArgumentException(StringPrintf("Expected receiver of type %s, but got %s",
- expected_class_name.c_str(),
- actual_class_name.c_str()).c_str());
- return false;
- }
- return true;
-}
-
mirror::Object* BoxPrimitive(Primitive::Type src_class, const JValue& value) {
if (src_class == Primitive::kPrimNot) {
return value.GetL();
@@ -810,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.
@@ -840,4 +824,12 @@ bool VerifyAccess(Thread* self, mirror::Object* obj, mirror::Class* declaring_cl
return declaring_class->IsInSamePackage(caller_class);
}
+void InvalidReceiverError(mirror::Object* o, mirror::Class* c) {
+ std::string expected_class_name(PrettyDescriptor(c));
+ std::string actual_class_name(PrettyTypeOf(o));
+ ThrowIllegalArgumentException(StringPrintf("Expected receiver of type %s, but got %s",
+ expected_class_name.c_str(),
+ actual_class_name.c_str()).c_str());
+}
+
} // namespace art