Fix a race condition in BaseBundle.
This CL fixes the race condition by ensuring that the parcel is not garbage collected after it's state has been checked
Change-Id: I59a1e4d1df44f123b6134665978c9a6c44be0710
Test: Presubmit tests
Bug: 324903437
diff --git a/core/java/android/os/BaseBundle.java b/core/java/android/os/BaseBundle.java
index 9a63394..49ab15a 100644
--- a/core/java/android/os/BaseBundle.java
+++ b/core/java/android/os/BaseBundle.java
@@ -429,10 +429,9 @@
"Lazy values ref count below 0");
// No more lazy values in mMap, so we can recycle the parcel early rather than
// waiting for the next GC run
- if (mLazyValues == 0) {
- Preconditions.checkState(mWeakParcelledData.get() != null,
- "Parcel recycled earlier than expected");
- recycleParcel(mWeakParcelledData.get());
+ Parcel parcel = mWeakParcelledData.get();
+ if (mLazyValues == 0 && parcel != null) {
+ recycleParcel(parcel);
mWeakParcelledData = null;
}
}