From d88c1499efe2f718f3cc1f45a3dc178471b22ce6 Mon Sep 17 00:00:00 2001 From: Nicolas Geoffray Date: Wed, 6 Jul 2022 10:01:58 +0100 Subject: 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 --- runtime/interpreter/interpreter_common.h | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'runtime/interpreter/interpreter_common.h') 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 receiver = - (type == kStatic) ? nullptr : shadow_frame.GetVRegReference(vregC); - ArtMethod* called_method; - called_method = FindMethodToCall( - 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 receiver = + (type == kStatic) ? nullptr : shadow_frame.GetVRegReference(vregC); + called_method = FindMethodToCall( + 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; } -- cgit v1.2.3-59-g8ed1b