OSDN Git Service

ART: JNI ExceptionDescribe crashes if no exception occurred
authorAlexei Zavjalov <alexei.zavjalov@intel.com>
Wed, 25 Jun 2014 09:04:55 +0000 (16:04 +0700)
committerAlexei Zavjalov <alexei.zavjalov@intel.com>
Wed, 2 Jul 2014 06:16:59 +0000 (13:16 +0700)
Some tests are calling ExceptionDescribe without checking if
we have an exception occurred. The most JVM's like Dalvik can
handle this in a good way, but art crashes with JNI error.

This adds a check in art::ExceptionDescribe for a case when it
called without exception.

Change-Id: Id9eddcc73e78b1197109be5a6340f9ff60940c74
Signed-off-by: Alexei Zavjalov <alexei.zavjalov@intel.com>
runtime/jni_internal.cc
runtime/jni_internal_test.cc

index 083f179..0624281 100644 (file)
@@ -684,6 +684,11 @@ class JNI {
   static void ExceptionDescribe(JNIEnv* env) {
     ScopedObjectAccess soa(env);
 
+    // If we have no exception to describe, pass through.
+    if (!soa.Self()->GetException(nullptr)) {
+      return;
+    }
+
     StackHandleScope<3> hs(soa.Self());
     // TODO: Use nullptr instead of null handles?
     auto old_throw_this_object(hs.NewHandle<mirror::Object>(nullptr));
index d255ec8..d50e094 100644 (file)
@@ -1472,6 +1472,12 @@ TEST_F(JniInternalTest, DeleteWeakGlobalRef) {
   env_->DeleteWeakGlobalRef(o2);
 }
 
+TEST_F(JniInternalTest, ExceptionDescribe) {
+  // This checks how ExceptionDescribe handles call without exception.
+  env_->ExceptionClear();
+  env_->ExceptionDescribe();
+}
+
 TEST_F(JniInternalTest, Throw) {
   EXPECT_EQ(JNI_ERR, env_->Throw(nullptr));