Fix regression in reflection on looking up equals/hashCode/toString in interface

Caused by 4266e50be8 and 8ccbbf71ec. Previously it worked because we
used hardcoded signatures of equals/hashCode/toString and always looked
them up in java.lang.Object

 #KT-25404 Fixed
This commit is contained in:
Alexander Udalov
2018-07-11 17:21:21 +02:00
parent 1f4dfbf5f3
commit 66b383349f
5 changed files with 61 additions and 2 deletions
@@ -168,9 +168,16 @@ internal abstract class KDeclarationContainerImpl : ClassBasedDeclarationContain
private fun Class<*>.lookupMethod(name: String, parameterTypes: List<Class<*>>, returnType: Class<*>, isPublic: Boolean): Method? {
val parametersArray = parameterTypes.toTypedArray()
// If we're looking for a public method, just use Java reflection's getMethod/getMethods
// If we're looking for a public method, use Java reflection's getMethod/getMethods first
if (isPublic) {
return tryGetMethod(name, parametersArray, returnType, declared = false)
val result = tryGetMethod(name, parametersArray, returnType, declared = false)
if (result != null) return result
// Methods from java.lang.Object cannot be found in the interface via Class.getMethod/getDeclaredMethod
if (isInterface) {
val fromObject = Any::class.java.lookupMethod(name, parameterTypes, returnType, isPublic)
if (fromObject != null) return fromObject
}
}
// If we're looking for a non-public method, it might be located not only in this class, but also in any of its superclasses