I have a Kotlin enum class. When I compile the release package, Redex warns me about a type mismatch issue. Its definition is as follows:
open class Config private constructor(val adapterType: AdapterType){
enum class AdapterType {
COMMON,
GLOBAL,
}
}
The Redex error is as Inconsistency found in Dex code for LX/1B3;.values$54379476:()[I, Lcom/model/Config$AdapterType;.values$54379476:()[I OK1. Type error in method Lcom/model/Config$AdapterType;.values$54379476:()[I at instruction 'INVOKE_VIRTUAL v0, [Ljava/lang/Object;.clone:()Ljava/lang/Object;' @ 0x7fe694164360 for : [I is not assignable to [Ljava/lang/Object;
I used Smali to check the classes.dex and found that this class was not correctly unboxed. The decompiled result is as follows:
# static fields
.field public static final COMMON$4f1f5ff0:I = 0x1
.field public static final GLOBAL$4f1f5ff0:I = 0x2
.field private static final synthetic L:[I
# direct methods
.method static constructor <clinit>()V
.registers 4
const/4 v0, 0x2
new-array v1, v0, [I
const/4 v2, 0x0
const/4 v3, 0x1
aput v3, v1, v2
aput v0, v1, v3
.line 35
sput-object v1, Lcom/a/a$a;->L:[I
return-void
.end method
.method public static values$54379476()[I
.registers 1
sget-object v0, Lcom/a/a$a;->L:[I
invoke-virtual {v0}, [Ljava/lang/Object;->clone()Ljava/lang/Object;
move-result-object v0
check-cast v0, [I
return-object v0
.end method
I see that the reason is Proguard does not replace the clone() to [I;->clone()Ljava/lang/Object;
after unboxing the enum type with I
, which led to the type mismatch error. However, this is the only enum in my entire package that triggered this error. I haven’t explicitly called the clone() or values() methods of this enum.
I resolved the issue by keeping this enum,
-keep enum com.model.Config$AdapterType {
*;
}
but I would like to know why this error occurred ?
Partholon is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.