You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by br...@apache.org on 2013/11/27 05:50:04 UTC

svn commit: r1545923 - /subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_class_cache.cpp

Author: brane
Date: Wed Nov 27 04:50:03 2013
New Revision: 1545923

URL: http://svn.apache.org/r1545923
Log:
Fix a silly thinko in exception handing during JavaHL library loading.

* subversion/bindings/javahl/native/jniwrapper/jni_class_cache.cpp
  (ClassCache::create): Explicitly handle the SignalExceptionThrown class.
   Do not use the JNI environment wrapper; we explicitly do not want to know
   about existing exceptions that are currently being thrown.

Modified:
    subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_class_cache.cpp

Modified: subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_class_cache.cpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_class_cache.cpp?rev=1545923&r1=1545922&r2=1545923&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_class_cache.cpp (original)
+++ subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_class_cache.cpp Wed Nov 27 04:50:03 2013
@@ -50,6 +50,8 @@ void ClassCache::create()
     {
       new ClassCache(Env());
     }
+  catch (const SignalExceptionThrown&)
+    {}
   catch (const std::exception& ex)
     {
       exception_message = ex.what();
@@ -59,23 +61,27 @@ void ClassCache::create()
       exception_message = "Caught unknown C++ exception";
     }
 
-  const ::Java::Env env;
-  if (exception_message || env.ExceptionCheck())
+  // Do not throw any more exceptions from here, so use the raw environment.
+  ::JNIEnv* const jenv = Env().get();
+  if (exception_message || jenv->ExceptionCheck())
     {
-      const jclass rtx = env.FindClass("java/lang/RuntimeException");
-      const jmethodID ctor = env.GetMethodID(rtx, "<init>",
-                                             "(Ljava/lang/String;"
-                                             "Ljava/lang/Throwable;)V");
-      jobject cause = env.ExceptionOccurred();
+      jobject cause = jenv->ExceptionOccurred();
+      if (cause)
+        jenv->ExceptionClear();
+
+      const jclass rtx = jenv->FindClass("java/lang/RuntimeException");
+      const jmethodID ctor = jenv->GetMethodID(rtx, "<init>",
+                                               "(Ljava/lang/String;"
+                                               "Ljava/lang/Throwable;)V");
       if (!cause && exception_message)
         {
-          const jstring msg = env.NewStringUTF(exception_message);
-          cause = env.NewObject(rtx, ctor, msg, jthrowable(0));
+          const jstring msg = jenv->NewStringUTF(exception_message);
+          cause = jenv->NewObject(rtx, ctor, msg, jthrowable(0));
         }
       const jstring reason =
-        env.NewStringUTF("JavaHL native library initialization failed");
-      const jobject exception = env.NewObject(rtx, ctor, reason, cause);
-      env.Throw(jthrowable(exception));
+        jenv->NewStringUTF("JavaHL native library initialization failed");
+      const jobject exception = jenv->NewObject(rtx, ctor, reason, cause);
+      jenv->Throw(jthrowable(exception));
     }
 }