From 41299287cf6538dbffd685d613a2f3ecd6ddda89 Mon Sep 17 00:00:00 2001 From: pyos Date: Fri, 26 Aug 2022 10:44:58 +0200 Subject: [PATCH] Remove incorrect override in TypeVariableImpl The correct return type of getAnnotatedBounds is Array. This fact causes some problems now that kotlin-stdlib is targeting JDK 1.8: * the compiler generates a bridge to the incorrect "override" that attempts to cast an empty Array into the correct type, which fails because those two types are unrelated; * on Android, touching this method in any way (via reflection) on any API version causes a ClassNotFoundException; * tools that validate references in libraries when compiling for Android complain about the bridge because they know the returned type does not exist. The easiest solution is to simply remove the override and leave getAnnotatedBounds unimplemented, making it throw AbstractMethodError when called. This is the behavior it previously had anyway, as kotlin-stdlib targeting JDK 1.6 lacked a method with the correct signature. --- libraries/stdlib/jvm/src/kotlin/reflect/TypesJVM.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libraries/stdlib/jvm/src/kotlin/reflect/TypesJVM.kt b/libraries/stdlib/jvm/src/kotlin/reflect/TypesJVM.kt index 88e631c37fa..ea56cdc67d3 100644 --- a/libraries/stdlib/jvm/src/kotlin/reflect/TypesJVM.kt +++ b/libraries/stdlib/jvm/src/kotlin/reflect/TypesJVM.kt @@ -136,8 +136,9 @@ private class TypeVariableImpl(private val typeParameter: KTypeParameter) : Type @Suppress("VIRTUAL_MEMBER_HIDDEN") fun getDeclaredAnnotations(): Array = emptyArray() - @Suppress("VIRTUAL_MEMBER_HIDDEN") - fun getAnnotatedBounds(): Array = emptyArray() + // There is also [getAnnotatedBounds] which returns an array of [AnnotatedType]; because [AnnotatedType] is JDK 8+, + // we can't declare that method here for compatibility with Android SDK 25 and lower, so we leave it unimplemented + // to throw an exception at runtime if called. } @ExperimentalStdlibApi