Fix incorrect interface-override linking
We would incorrectly search all declared methods when searching for
overrides of super-class interface methods. This could lead to
incorrect behavior since we could try to override methods with static
or private methods. This could cause exceptions or other issues.
This fixes a typo from over 4 years ago in go/aog/185608 and restores
the behavior we had prior to N.
Bug: 152199517
Test: ./test.py --host
Change-Id: Ic6ce51f79d071727316bb39e5bbeabb92cb4aa9a
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index 3376bdd..27bdfe6 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -8155,7 +8155,7 @@
// If we are overwriting a super class interface, try to only virtual methods instead of the
// whole vtable.
using_virtuals = true;
- input_virtual_methods = klass->GetDeclaredMethodsSlice(image_pointer_size_);
+ input_virtual_methods = klass->GetDeclaredVirtualMethodsSlice(image_pointer_size_);
input_array_length = input_virtual_methods.size();
} else {
// For a new interface, however, we need the whole vtable in case a new
@@ -8191,6 +8191,7 @@
input_vtable_array->GetElementPtrSize<ArtMethod*>(k, image_pointer_size_);
ArtMethod* vtable_method_for_name_comparison =
vtable_method->GetInterfaceMethodIfProxy(image_pointer_size_);
+ DCHECK(!vtable_method->IsStatic()) << vtable_method->PrettyMethod();
if (interface_name_comparator.HasSameNameAndSignature(
vtable_method_for_name_comparison)) {
if (!vtable_method->IsAbstract() && !vtable_method->IsPublic()) {