Disable uninitialized object copying checks for Parcelable writeToParcel() to createFromParcel()

This commit is contained in:
Yan Zhulanow
2017-10-12 19:18:13 +03:00
parent 824e0a072e
commit 5acc992956
2 changed files with 15 additions and 1 deletions
@@ -75,6 +75,11 @@ class UninitializedStoresProcessor(
private val methodNode: MethodNode,
private val shouldPreserveClassInitialization: Boolean
) {
companion object {
val AVOID_UNINITIALIZED_OBJECT_COPYING_CHECK_ANNOTATION_DESCRIPTOR =
"Lkotlin/internal/annotations/AvoidUninitializedObjectCopyingCheck;"
}
// <init> method is "special", because it will invoke <init> from this class or from a base class for #0
//
// <clinit> method is "special", because <clinit> for singleton objects is generated as:
@@ -83,7 +88,11 @@ class UninitializedStoresProcessor(
// and the newly created value is dropped.
private val isInSpecialMethod = methodNode.name == "<init>" || methodNode.name == "<clinit>"
private val shouldCheckUninitializedObjectCopy = !methodNode.invisibleAnnotations.orEmpty()
.any { it.desc == AVOID_UNINITIALIZED_OBJECT_COPYING_CHECK_ANNOTATION_DESCRIPTOR }
fun run() {
if (!shouldCheckUninitializedObjectCopy) return
val interpreter = UninitializedNewValueMarkerInterpreter(methodNode.instructions)
val frames = CustomFramesMethodAnalyzer(
@@ -174,7 +183,7 @@ class UninitializedStoresProcessor(
assert(insn.opcode == Opcodes.INVOKESPECIAL) { "Expected opcode Opcodes.INVOKESPECIAL for <init>, but ${insn.opcode} found" }
val paramsCountIncludingReceiver = Type.getArgumentTypes((insn as MethodInsnNode).desc).size + 1
val newValue = peek(paramsCountIncludingReceiver) as? UninitializedNewValue ?:
if (isInSpecialMethod)
if (isInSpecialMethod || !shouldCheckUninitializedObjectCopy)
return null
else
error("Expected value generated with NEW")