Take hidden API into account during getDeclaredMethod()
Generics make it possible for two methods to have the same name and list
of parameters but differ in their return type. Class.getDeclaredMethod()
does not allow callers to specify the type, so either of the matching
methods can be returned (ART will prefer the non-synthetic one).
However, Class::GetDeclaredMethodInternal() did not use to take hidden API
into account and could return a hidden method, despite a non-hidden one
being available. The reflective call would then reject the method and
throw NoSuchMethodException.
This patch modifies Class:GetDeclaredMethodInternal() to consider:
(a) hidden/non-hidden
(b) virtual/direct
(c) synthetic/non-synthetic
in that decreasing order of importance and pick the best matching
method. The hiddenness checks are performed with AccessMethod::kNone
so as to not trigger warnings. A hidden method may still be returned and
the caller should do the access check again with the appropriate
AccessMethod.
Bug: 122291025
Test: art/test.py -r -t 690-hiddenapi-same-name-methods
Change-Id: Iaee780c1e87f5587f51e24b517b2b37101c729e3
diff --git a/test/knownfailures.json b/test/knownfailures.json
index 9c01ba9..b9a0963 100644
--- a/test/knownfailures.json
+++ b/test/knownfailures.json
@@ -534,8 +534,9 @@
"097-duplicate-method",
"138-duplicate-classes-check2",
"159-app-image-fields",
- "674-hiddenapi",
"649-vdex-duplicate-method",
+ "674-hiddenapi",
+ "690-hiddenapi-same-name-methods",
"804-class-extends-itself",
"921-hello-failure",
"999-redefine-hiddenapi"
@@ -555,6 +556,7 @@
"629-vdex-speed",
"647-jni-get-field-id",
"674-hiddenapi",
+ "690-hiddenapi-same-name-methods",
"944-transform-classloaders",
"999-redefine-hiddenapi"
],
@@ -1085,6 +1087,7 @@
"678-quickening",
"679-locks",
"688-shared-library",
+ "690-hiddenapi-same-name-methods",
"999-redefine-hiddenapi",
"1000-non-moving-space-stress",
"1001-app-image-regions",