diff options
author | 2022-07-06 10:01:58 +0100 | |
---|---|---|
committer | 2022-07-07 16:58:21 +0000 | |
commit | d88c1499efe2f718f3cc1f45a3dc178471b22ce6 (patch) | |
tree | d28e20d9a4f87d2c1fc9a867b111cdc818ff250a /runtime/class_linker.cc | |
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/class_linker.cc')
-rw-r--r-- | runtime/class_linker.cc | 22 |
1 files changed, 2 insertions, 20 deletions
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc index d21aecc2fa..c2ce3e2eb8 100644 --- a/runtime/class_linker.cc +++ b/runtime/class_linker.cc @@ -7857,20 +7857,6 @@ bool ClassLinker::LinkMethodsHelper<kPointerSize>::FinalizeIfTable( return true; } -NO_INLINE -static void ThrowIllegalAccessErrorForImplementingMethod(ObjPtr<mirror::Class> klass, - ArtMethod* vtable_method, - ArtMethod* interface_method) - REQUIRES_SHARED(Locks::mutator_lock_) { - DCHECK(!vtable_method->IsAbstract()); - DCHECK(!vtable_method->IsPublic()); - ThrowIllegalAccessError( - klass, - "Method '%s' implementing interface method '%s' is not public", - vtable_method->PrettyMethod().c_str(), - interface_method->PrettyMethod().c_str()); -} - template <PointerSize kPointerSize> ObjPtr<mirror::PointerArray> ClassLinker::LinkMethodsHelper<kPointerSize>::AllocPointerArray( Thread* self, size_t length) { @@ -8124,15 +8110,11 @@ size_t ClassLinker::LinkMethodsHelper<kPointerSize>::AssignVTableIndexes( found = true; } } + found = found && vtable_method->IsPublic(); + uint32_t vtable_index = vtable_length; if (found) { DCHECK(vtable_method != nullptr); - if (!vtable_method->IsAbstract() && !vtable_method->IsPublic()) { - // FIXME: Delay the exception until we actually try to call the method. b/211854716 - sants.reset(); - ThrowIllegalAccessErrorForImplementingMethod(klass, vtable_method, interface_method); - return 0u; - } vtable_index = vtable_method->GetMethodIndexDuringLinking(); if (!vtable_method->IsOverridableByDefaultMethod()) { method_array->SetElementPtrSize(j, vtable_index, kPointerSize); |