Fix reading exception from Parcel
It fails to read exception from Parcel using
Parcel#readException(int, String) because this method doesn't take into
account the remote stack trace info added in writeException().
Test: Manual
Bug: 77495513
Change-Id: I7b646b4a591306832897a42c4ed205d00019cc2b
diff --git a/core/java/android/os/Parcel.java b/core/java/android/os/Parcel.java
index e3c4870..5142928 100644
--- a/core/java/android/os/Parcel.java
+++ b/core/java/android/os/Parcel.java
@@ -1857,26 +1857,7 @@
int code = readExceptionCode();
if (code != 0) {
String msg = readString();
- String remoteStackTrace = null;
- final int remoteStackPayloadSize = readInt();
- if (remoteStackPayloadSize > 0) {
- remoteStackTrace = readString();
- }
- Exception e = createException(code, msg);
- // Attach remote stack trace if availalble
- if (remoteStackTrace != null) {
- RemoteException cause = new RemoteException(
- "Remote stack trace:\n" + remoteStackTrace, null, false, false);
- 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);
+ readException(code, msg);
}
}
@@ -1921,7 +1902,26 @@
* @param msg The exception message.
*/
public final void readException(int code, String msg) {
- SneakyThrow.sneakyThrow(createException(code, msg));
+ String remoteStackTrace = null;
+ final int remoteStackPayloadSize = readInt();
+ if (remoteStackPayloadSize > 0) {
+ remoteStackTrace = readString();
+ }
+ Exception e = createException(code, msg);
+ // Attach remote stack trace if availalble
+ if (remoteStackTrace != null) {
+ RemoteException cause = new RemoteException(
+ "Remote stack trace:\n" + remoteStackTrace, null, false, false);
+ 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);
}
/**