-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
KTOR-7479 Quick fix for compatibility with R8 full mode #4369
Conversation
a55d4c8
to
377d595
Compare
// kType != null always returns false, so we try to get javaType anyway | ||
kType!!.javaType | ||
} catch (_: NullPointerException) { | ||
// Fallback to a type without generics if we can't get KType for the given T | ||
T::class.java |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will create an issue in the Kotlin project and mention its number here
object : ClientPlugin<PluginConfigT> { | ||
override val key: AttributeKey<ClientPluginInstance<PluginConfigT>> = AttributeKey(name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One of the problems was here because. typeOf
call on a generic type inside a non-inline function produces something like this:
KTypeParameter var10006 = Reflection.typeParameter(new FunctionReferenceImpl(3, CreatePluginUtilsKt.class, "createClientPlugin", "createClientPlugin(Ljava/lang/String;Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function1;)Lio/ktor/client/plugins/api/ClientPlugin;", 1), "PluginConfigT", KVariance.INVARIANT, false);
And it doesn't work after obfuscation.
377d595
to
55a72a6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, nice sleuthing 👍
8f73aae
to
4127dcb
Compare
Subsystem
Client/Server
Motivation
KTOR-7479 -
createClientPlugin
fails in runtime if an application is obfuscated with ProGuard/R8.Solution
The problem occurs when
typeOf
is called with a generic type (ex.typeOf<List<T>>
whereT
is specified in function or class signature).typeOf
relies on class attributes which are stripped if R8 is running in full mode.The first problem is straightforward to solve, while the second one is tricky. As a quick solution, we just use a type without generics in case generics can't be retrieved from class attributes.
It is better to review commit-by-commit