diff options
author | 2022-06-24 21:53:32 +0000 | |
---|---|---|
committer | 2022-06-24 21:53:32 +0000 | |
commit | 6db478c840ca7f0e968fb3bbd0d02ba37cb08c20 (patch) | |
tree | ee31ad30e91ee3d506ebdefa06b8c04f73017e9a | |
parent | 2b11e008d2063bb1fc78e5aa23695199ec28228a (diff) | |
parent | 710f81728645530283164731588d503ddecac3c8 (diff) |
Merge "Parcel: better debug recycle"
-rw-r--r-- | core/java/android/os/Parcel.java | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/core/java/android/os/Parcel.java b/core/java/android/os/Parcel.java index 6411f424e7e0..40e678085445 100644 --- a/core/java/android/os/Parcel.java +++ b/core/java/android/os/Parcel.java @@ -247,6 +247,7 @@ public final class Parcel { private ArrayMap<Class, Object> mClassCookies; private RuntimeException mStack; + private boolean mRecycled = false; /** @hide */ @TestApi @@ -528,6 +529,7 @@ public final class Parcel { if (res == null) { res = new Parcel(0); } else { + res.mRecycled = false; if (DEBUG_RECYCLE) { res.mStack = new RuntimeException(); } @@ -556,7 +558,15 @@ public final class Parcel { * the object after this call. */ public final void recycle() { - if (DEBUG_RECYCLE) mStack = null; + if (mRecycled) { + Log.w(TAG, "Recycle called on unowned Parcel. (recycle twice?)", mStack); + } + mRecycled = true; + + // We try to reset the entire object here, but in order to be + // able to print a stack when a Parcel is recycled twice, that + // is cleared in obtain instead. + mClassCookies = null; freeBuffer(); @@ -5105,6 +5115,7 @@ public final class Parcel { if (res == null) { res = new Parcel(obj); } else { + res.mRecycled = false; if (DEBUG_RECYCLE) { res.mStack = new RuntimeException(); } @@ -5153,7 +5164,8 @@ public final class Parcel { @Override protected void finalize() throws Throwable { if (DEBUG_RECYCLE) { - if (mStack != null) { + // we could always have this log on, but it's spammy + if (!mRecycled) { Log.w(TAG, "Client did not call Parcel.recycle()", mStack); } } |