Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2214b828 authored by Takamasa Kuramitsu's avatar Takamasa Kuramitsu Committed by Fyodor Kupolov
Browse files

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
parent 7ee86d1d
Loading
Loading
Loading
Loading
+21 −21
Original line number Diff line number Diff line
@@ -1857,26 +1857,7 @@ public final class Parcel {
        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 @@ public final class Parcel {
     * @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);
    }

    /**