From 0e51db779316533b3b0cd4d70ac419910480785b Mon Sep 17 00:00:00 2001 From: Mygod Date: Tue, 14 Jul 2020 11:37:14 -0400 Subject: [PATCH] Implement Object methods correctly --- .../src/main/java/be/mygod/vpnhotspot/util/Utils.kt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/util/Utils.kt b/mobile/src/main/java/be/mygod/vpnhotspot/util/Utils.kt index 411a114c..ab069c91 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/util/Utils.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/util/Utils.kt @@ -146,7 +146,16 @@ fun InvocationHandler.callSuper(interfaceClass: Class<*>, proxy: Any, method: Me if (args == null) invokeWithArguments() else invokeWithArguments(*args) } // otherwise, we just redispatch it to InvocationHandler - method.declaringClass.isAssignableFrom(javaClass) -> if (args == null) method(this) else method(this, *args) + method.declaringClass.isAssignableFrom(javaClass) -> when { + method.declaringClass == Object::class.java -> when (method.name) { + "hashCode" -> System.identityHashCode(proxy) + "equals" -> proxy === args!![0] + "toString" -> "${proxy.javaClass.name}@${System.identityHashCode(proxy).toString(16)}" + else -> error("Unsupported Object method dispatched") + } + args == null -> method(this) + else -> method(this, *args) + } else -> { Timber.w("Unhandled method: $method(${args?.contentDeepToString()})") null