diff options
author | 2022-07-06 10:01:58 +0100 | |
---|---|---|
committer | 2022-07-07 16:58:21 +0000 | |
commit | d88c1499efe2f718f3cc1f45a3dc178471b22ce6 (patch) | |
tree | d28e20d9a4f87d2c1fc9a867b111cdc818ff250a /runtime/interpreter/interpreter_common.h | |
parent | 4a21275dfb1bc58ede8141cbfd103ad46c3fcf2d (diff) |
Fix one edge case at method linking to throw at runtime.
If we could not find a public implementation for a public method, throw
an IllegalAccessError at runtime, when the method is actually called,
instead of when the class is being created.
Test: 840-resolution
Test: 182-method-linking
Change-Id: I741c7d0f6fc3b90a5d1614e1a9b76985a2eb32e2
Diffstat (limited to 'runtime/interpreter/interpreter_common.h')
-rw-r--r-- | runtime/interpreter/interpreter_common.h | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/runtime/interpreter/interpreter_common.h b/runtime/interpreter/interpreter_common.h index 0b91120c58..fe9cf57ec5 100644 --- a/runtime/interpreter/interpreter_common.h +++ b/runtime/interpreter/interpreter_common.h @@ -259,18 +259,23 @@ static ALWAYS_INLINE bool DoInvoke(Thread* self, } // Null pointer check and virtual method resolution. - ObjPtr<mirror::Object> receiver = - (type == kStatic) ? nullptr : shadow_frame.GetVRegReference(vregC); - ArtMethod* called_method; - called_method = FindMethodToCall<type, do_access_check>( - method_idx, resolved_method, &receiver, sf_method, self); - if (UNLIKELY(called_method == nullptr)) { - CHECK(self->IsExceptionPending()); - result->SetJ(0); - return false; + ArtMethod* called_method = nullptr; + { + // `FindMethodToCall` might suspend, so don't keep `receiver` as a local + // variable after the call. + ObjPtr<mirror::Object> receiver = + (type == kStatic) ? nullptr : shadow_frame.GetVRegReference(vregC); + called_method = FindMethodToCall<type, do_access_check>( + method_idx, resolved_method, &receiver, sf_method, self); + if (UNLIKELY(called_method == nullptr)) { + CHECK(self->IsExceptionPending()); + result->SetJ(0); + return false; + } } if (UNLIKELY(!called_method->IsInvokable())) { - called_method->ThrowInvocationTimeError(); + called_method->ThrowInvocationTimeError( + (type == kStatic) ? nullptr : shadow_frame.GetVRegReference(vregC)); result->SetJ(0); return false; } |