Disable uninitialized object copying checks for Parcelable writeToParcel() to createFromParcel()
This commit is contained in:
+10
-1
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user