From 3b946f43a430f9c2b4d65148984dd77748991023 Mon Sep 17 00:00:00 2001 From: Fyodor Kupolov Date: Mon, 27 Nov 2017 10:40:46 -0800 Subject: [PATCH] Use the root case to set remote stack trace for Otherwise it may cause ISE if a cause has already been set like in ParcelableException. Test: manual install/uninstall an app on secondary user Bug: 69704045 Change-Id: Ia8631ea76d5acf38e60fc609eef65f010ade21b5 --- core/java/android/os/Parcel.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/core/java/android/os/Parcel.java b/core/java/android/os/Parcel.java index 36121d452d967..62bb38540e449 100644 --- a/core/java/android/os/Parcel.java +++ b/core/java/android/os/Parcel.java @@ -20,6 +20,7 @@ import android.annotation.Nullable; import android.text.TextUtils; import android.util.ArrayMap; import android.util.ArraySet; +import android.util.ExceptionUtils; import android.util.Log; import android.util.Size; import android.util.SizeF; @@ -1866,7 +1867,14 @@ public final class Parcel { if (remoteStackTrace != null) { RemoteException cause = new RemoteException( "Remote stack trace:\n" + remoteStackTrace, null, false, false); - e.initCause(cause); + try { + Throwable rootCause = ExceptionUtils.getRootCause(e); + if (rootCause != null) { + rootCause.initCause(cause); + } + } catch (RuntimeException ex) { + Log.e(TAG, "Cannot set cause " + cause + " for " + e, ex); + } } SneakyThrow.sneakyThrow(e); }