mirror of
https://github.com/fankes/moshi.git
synced 2025-10-19 07:59:21 +08:00
Always check for DefaultConstructorMarker class (#1038)
Reported by a Googler - We currently gate the lookup of the class on the presence of `Metadata`. However, `Metadata` might be justifiably stripped by Proguard/R8, even though `DefaultConstructorMarker` might still be present. This means Moshi's defaults invocation is likely broken on (at least) R8 builds without this. Workaround until next release is to keep Metadata annotations
This commit is contained in:
@@ -52,13 +52,20 @@ public final class Util {
|
||||
|
||||
static {
|
||||
Class<? extends Annotation> metadata = null;
|
||||
Class<?> defaultConstructorMarker = null;
|
||||
try {
|
||||
//noinspection unchecked
|
||||
metadata = (Class<? extends Annotation>) Class.forName("kotlin.Metadata");
|
||||
defaultConstructorMarker = Class.forName("kotlin.jvm.internal.DefaultConstructorMarker");
|
||||
} catch (ClassNotFoundException ignored) {
|
||||
}
|
||||
METADATA = metadata;
|
||||
|
||||
// We look up the constructor marker separately because Metadata might be (justifiably)
|
||||
// stripped by R8/Proguard but the DefaultConstructorMarker is still present.
|
||||
Class<?> defaultConstructorMarker = null;
|
||||
try {
|
||||
defaultConstructorMarker = Class.forName("kotlin.jvm.internal.DefaultConstructorMarker");
|
||||
} catch (ClassNotFoundException ignored) {
|
||||
}
|
||||
DEFAULT_CONSTRUCTOR_MARKER = defaultConstructorMarker;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user