You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by sv...@apache.org on 2014/04/17 09:46:42 UTC

svn commit: r1588152 - in /subversion/branches/1.8.x: ./ subversion/bindings/javahl/native/JNIUtil.cpp subversion/bindings/javahl/native/JNIUtil.h

Author: svn-role
Date: Thu Apr 17 07:46:42 2014
New Revision: 1588152

URL: http://svn.apache.org/r1588152
Log:
Merge the 1.8.x-javahl-exception-crash branch:

 * r1586439
   Fix a crash in JavaHL that was reported on the users@ list and is
   already fixed on trunk.
   Justification:
     JavaHL should not crash the JVM too often.
   Notes:
     The original report is here:
     http://mail-archives.apache.org/mod_mbox/subversion-users/201404.mbox/%3CCAAVTFFjrZEy-PT3i1xu0mOM_AC89-237CmFEZ7QYcJxNckfEtA%40mail.gmail.com%3E
   Branch:
     ^/subversion/branches/1.8.x-javahl-exception-crash
   Votes:
     +1: brane, rhuijben

Modified:
    subversion/branches/1.8.x/   (props changed)
    subversion/branches/1.8.x/subversion/bindings/javahl/native/JNIUtil.cpp
    subversion/branches/1.8.x/subversion/bindings/javahl/native/JNIUtil.h

Propchange: subversion/branches/1.8.x/
------------------------------------------------------------------------------
  Merged /subversion/branches/1.8.x-javahl-exception-crash:r1586424-1588151

Modified: subversion/branches/1.8.x/subversion/bindings/javahl/native/JNIUtil.cpp
URL: http://svn.apache.org/viewvc/subversion/branches/1.8.x/subversion/bindings/javahl/native/JNIUtil.cpp?rev=1588152&r1=1588151&r2=1588152&view=diff
==============================================================================
--- subversion/branches/1.8.x/subversion/bindings/javahl/native/JNIUtil.cpp (original)
+++ subversion/branches/1.8.x/subversion/bindings/javahl/native/JNIUtil.cpp Thu Apr 17 07:46:42 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/subversion/bindings/javahl/native/JNIUtil.h
URL: http://svn.apache.org/viewvc/subversion/branches/1.8.x/subversion/bindings/javahl/native/JNIUtil.h?rev=1588152&r1=1588151&r2=1588152&view=diff
==============================================================================
--- subversion/branches/1.8.x/subversion/bindings/javahl/native/JNIUtil.h (original)
+++ subversion/branches/1.8.x/subversion/bindings/javahl/native/JNIUtil.h Thu Apr 17 07:46:42 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);