From f0aa0f1242346870d8546c2bbd6c556f94a9f38c Mon Sep 17 00:00:00 2001 From: Aurimas Liutikas Date: Fri, 10 Feb 2017 14:52:59 -0800 Subject: [PATCH] Clear exceptions before calling IsInstanceOf. Test: None Change-Id: Iac94f4d7c489c1062a757919fd12a343b8abd001 --- core/jni/android_os_HwBinder.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/jni/android_os_HwBinder.cpp b/core/jni/android_os_HwBinder.cpp index c1d42513963d6..989a557986c43 100644 --- a/core/jni/android_os_HwBinder.cpp +++ b/core/jni/android_os_HwBinder.cpp @@ -157,13 +157,15 @@ status_t JHwBinder::onTransact( if (env->ExceptionCheck()) { jthrowable excep = env->ExceptionOccurred(); env->ExceptionDescribe(); + env->ExceptionClear(); + // It is illegal to call IsInstanceOf if there is a pending exception. + // Attempting to do so results in a JniAbort which crashes the entire process. if (env->IsInstanceOf(excep, gErrorClass)) { /* It's an error */ LOG(ERROR) << "Forcefully exiting"; exit(1); } else { - env->ExceptionClear(); LOG(ERROR) << "Uncaught exception!"; }