Skip to content

Commit 5acc992

Browse files
committed
Disable uninitialized object copying checks for Parcelable writeToParcel() to createFromParcel()
1 parent 824e0a0 commit 5acc992

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/processUninitializedStores.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ class UninitializedStoresProcessor(
7575
private val methodNode: MethodNode,
7676
private val shouldPreserveClassInitialization: Boolean
7777
) {
78+
companion object {
79+
val AVOID_UNINITIALIZED_OBJECT_COPYING_CHECK_ANNOTATION_DESCRIPTOR =
80+
"Lkotlin/internal/annotations/AvoidUninitializedObjectCopyingCheck;"
81+
}
82+
7883
// <init> method is "special", because it will invoke <init> from this class or from a base class for #0
7984
//
8085
// <clinit> method is "special", because <clinit> for singleton objects is generated as:
@@ -83,7 +88,11 @@ class UninitializedStoresProcessor(
8388
// and the newly created value is dropped.
8489
private val isInSpecialMethod = methodNode.name == "<init>" || methodNode.name == "<clinit>"
8590

91+
private val shouldCheckUninitializedObjectCopy = !methodNode.invisibleAnnotations.orEmpty()
92+
.any { it.desc == AVOID_UNINITIALIZED_OBJECT_COPYING_CHECK_ANNOTATION_DESCRIPTOR }
93+
8694
fun run() {
95+
if (!shouldCheckUninitializedObjectCopy) return
8796
val interpreter = UninitializedNewValueMarkerInterpreter(methodNode.instructions)
8897

8998
val frames = CustomFramesMethodAnalyzer(
@@ -174,7 +183,7 @@ class UninitializedStoresProcessor(
174183
assert(insn.opcode == Opcodes.INVOKESPECIAL) { "Expected opcode Opcodes.INVOKESPECIAL for <init>, but ${insn.opcode} found" }
175184
val paramsCountIncludingReceiver = Type.getArgumentTypes((insn as MethodInsnNode).desc).size + 1
176185
val newValue = peek(paramsCountIncludingReceiver) as? UninitializedNewValue ?:
177-
if (isInSpecialMethod)
186+
if (isInSpecialMethod || !shouldCheckUninitializedObjectCopy)
178187
return null
179188
else
180189
error("Expected value generated with NEW")

plugins/android-extensions/android-extensions-compiler/src/org/jetbrains/kotlin/android/parcel/ParcelableCodegenExtension.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature
3333
import org.jetbrains.kotlin.codegen.FunctionGenerationStrategy.CodegenBased
3434
import org.jetbrains.kotlin.codegen.OwnerKind
3535
import org.jetbrains.kotlin.codegen.context.ClassContext
36+
import org.jetbrains.kotlin.codegen.coroutines.UninitializedStoresProcessor
3637
import org.jetbrains.kotlin.codegen.writeSyntheticClassMetadata
3738
import org.jetbrains.kotlin.descriptors.impl.ClassDescriptorImpl
3839
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
@@ -100,6 +101,8 @@ open class ParcelableCodegenExtension : ExpressionCodegenExtension {
100101
val containerAsmType = codegen.typeMapper.mapType(this.defaultType)
101102

102103
return findFunction(WRITE_TO_PARCEL)?.write(codegen) {
104+
v.visitAnnotation(UninitializedStoresProcessor.AVOID_UNINITIALIZED_OBJECT_COPYING_CHECK_ANNOTATION_DESCRIPTOR, false)
105+
103106
if (parcelerObject != null) {
104107
val (companionAsmType, companionFieldName) = getCompanionClassType(containerAsmType, parcelerObject)
105108

@@ -178,6 +181,8 @@ open class ParcelableCodegenExtension : ExpressionCodegenExtension {
178181
val containerAsmType = codegen.typeMapper.mapType(parcelableClass)
179182

180183
createMethod(creatorClass, CREATE_FROM_PARCEL, parcelableClass.builtIns.anyType, "in" to parcelClassType).write(codegen) {
184+
v.visitAnnotation(UninitializedStoresProcessor.AVOID_UNINITIALIZED_OBJECT_COPYING_CHECK_ANNOTATION_DESCRIPTOR, false)
185+
181186
if (parcelerObject != null) {
182187
val (companionAsmType, companionFieldName) = getCompanionClassType(containerAsmType, parcelerObject)
183188

0 commit comments

Comments
 (0)