subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r1586439 - in /subversion/branches/1.8.x-javahl-exception-crash/subversion/bindings/javahl/native: JNIUtil.cpp JNIUtil.h
Date Thu, 10 Apr 2014 19:31:58 GMT
Author: brane
Date: Thu Apr 10 19:31:57 2014
New Revision: 1586439

URL: http://svn.apache.org/r1586439
Log:
On the 1.8.x-javahl-exception-crash branch:
Manually backport the fix from trunk JavaHL.

[in subversion/bindings/javahl]

* native/JNIUtil.h (JNIUtil::wrappedHandleSVNError):
   Declare new private method.
* native/JNIUtil.cpp
  (JNIUtil::wrappedHandleSVNError): Renamed from JNIUtil::handleSVNError.
   Removed the bit that (only sometimes) clears the SVN error.
  (JNIUtil::handleSVNError): New wrapper for above that always clears the error.
  (JNIUtil::thrownExceptionToCString): Use the concrete exception class
   to retreive the message, and never return a NULL message if an exception
   was thrown.

Modified:
    subversion/branches/1.8.x-javahl-exception-crash/subversion/bindings/javahl/native/JNIUtil.cpp
    subversion/branches/1.8.x-javahl-exception-crash/subversion/bindings/javahl/native/JNIUtil.h

Modified: subversion/branches/1.8.x-javahl-exception-crash/subversion/bindings/javahl/native/JNIUtil.cpp
URL: http://svn.apache.org/viewvc/subversion/branches/1.8.x-javahl-exception-crash/subversion/bindings/javahl/native/JNIUtil.cpp?rev=1586439&r1=1586438&r2=1586439&view=diff
==============================================================================
--- subversion/branches/1.8.x-javahl-exception-crash/subversion/bindings/javahl/native/JNIUtil.cpp
(original)
+++ subversion/branches/1.8.x-javahl-exception-crash/subversion/bindings/javahl/native/JNIUtil.cpp
Thu Apr 10 19:31:57 2014
@@ -418,7 +418,7 @@ JNIUtil::putErrorsInTrace(svn_error_t *e
   env->DeleteLocalRef(jfileName);
 }
 
-void JNIUtil::handleSVNError(svn_error_t *err)
+void JNIUtil::wrappedHandleSVNError(svn_error_t *err)
 {
   std::string msg;
   assembleErrorMessage(svn_error_purge_tracing(err), 0, APR_SUCCESS, msg);
@@ -546,7 +546,16 @@ void JNIUtil::handleSVNError(svn_error_t
 #endif
 
   env->Throw(static_cast<jthrowable>(env->PopLocalFrame(nativeException)));
+}
 
+void JNIUtil::handleSVNError(svn_error_t *err)
+{
+  try {
+    wrappedHandleSVNError(err);
+  } catch (...) {
+    svn_error_clear(err);
+    throw;
+  }
   svn_error_clear(err);
 }
 
@@ -646,28 +655,42 @@ bool JNIUtil::isJavaExceptionThrown()
 const char *
 JNIUtil::thrownExceptionToCString(SVN::Pool &in_pool)
 {
-  const char *msg;
+  const char *msg = NULL;
   JNIEnv *env = getEnv();
+  apr_pool_t *pool = in_pool.getPool();
   if (env->ExceptionCheck())
     {
       jthrowable t = env->ExceptionOccurred();
-      static jmethodID getMessage = 0;
-      if (getMessage == 0)
+      jclass cls = env->GetObjectClass(t);
+
+      jstring jclass_name;
+      {
+        jmethodID mid = env->GetMethodID(cls, "getClass", "()Ljava/lang/Class;");
+        jobject clsobj = env->CallObjectMethod(t, mid);
+        jclass basecls = env->GetObjectClass(clsobj);
+        mid = env->GetMethodID(basecls, "getName", "()Ljava/lang/String;");
+        jclass_name = (jstring) env->CallObjectMethod(clsobj, mid);
+      }
+
+      jstring jmessage;
+      {
+        jmethodID mid = env->GetMethodID(cls, "getMessage",
+                                         "()Ljava/lang/String;");
+        jmessage = (jstring) env->CallObjectMethod(t, mid);
+      }
+
+      JNIStringHolder class_name(jclass_name);
+      if (jmessage)
         {
-          jclass clazz = env->FindClass("java/lang/Throwable");
-          getMessage = env->GetMethodID(clazz, "getMessage",
-                                        "(V)Ljava/lang/String;");
-          env->DeleteLocalRef(clazz);
+          JNIStringHolder message(jmessage);
+          msg = apr_pstrcat(pool,
+                            static_cast<const char*>(class_name), ": ",
+                            static_cast<const char*>(message), NULL);
         }
-      jstring jmsg = (jstring) env->CallObjectMethod(t, getMessage);
-      JNIStringHolder tmp(jmsg);
-      msg = tmp.pstrdup(in_pool.getPool());
+      else
+        msg = class_name.pstrdup(pool);
       // ### Conditionally add t.printStackTrace() to msg?
     }
-  else
-    {
-      msg = NULL;
-    }
   return msg;
 }
 

Modified: subversion/branches/1.8.x-javahl-exception-crash/subversion/bindings/javahl/native/JNIUtil.h
URL: http://svn.apache.org/viewvc/subversion/branches/1.8.x-javahl-exception-crash/subversion/bindings/javahl/native/JNIUtil.h?rev=1586439&r1=1586438&r2=1586439&view=diff
==============================================================================
--- subversion/branches/1.8.x-javahl-exception-crash/subversion/bindings/javahl/native/JNIUtil.h
(original)
+++ subversion/branches/1.8.x-javahl-exception-crash/subversion/bindings/javahl/native/JNIUtil.h
Thu Apr 10 19:31:57 2014
@@ -141,6 +141,7 @@ class JNIUtil
   enum { noLog, errorLog, exceptionLog, entryLog } LogLevel;
 
  private:
+  static void wrappedHandleSVNError(svn_error_t *err);
   static void assembleErrorMessage(svn_error_t *err, int depth,
                                    apr_status_t parent_apr_err,
                                    std::string &buffer);



Mime
View raw message