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 2014/04/10 22:24:08 UTC

svn commit: r1586463 - in /subversion/branches/1.7.x-javahl-exception-crash: ./ subversion/bindings/javahl/native/ClientContext.cpp subversion/bindings/javahl/native/JNIUtil.cpp subversion/bindings/javahl/native/JNIUtil.h

Author: brane
Date: Thu Apr 10 20:24:08 2014
New Revision: 1586463

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

[in subversion/bindings/javahl]

* native/ClientContext.cpp
  (ClientContext::resolve): Make sure the result is always predictable.
* 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.7.x-javahl-exception-crash/   (props changed)
    subversion/branches/1.7.x-javahl-exception-crash/subversion/bindings/javahl/native/ClientContext.cpp
    subversion/branches/1.7.x-javahl-exception-crash/subversion/bindings/javahl/native/JNIUtil.cpp
    subversion/branches/1.7.x-javahl-exception-crash/subversion/bindings/javahl/native/JNIUtil.h

Propchange: subversion/branches/1.7.x-javahl-exception-crash/
------------------------------------------------------------------------------
  Merged /subversion/branches/1.8.x-javahl-exception-crash:r1586439

Modified: subversion/branches/1.7.x-javahl-exception-crash/subversion/bindings/javahl/native/ClientContext.cpp
URL: http://svn.apache.org/viewvc/subversion/branches/1.7.x-javahl-exception-crash/subversion/bindings/javahl/native/ClientContext.cpp?rev=1586463&r1=1586462&r2=1586463&view=diff
==============================================================================
--- subversion/branches/1.7.x-javahl-exception-crash/subversion/bindings/javahl/native/ClientContext.cpp (original)
+++ subversion/branches/1.7.x-javahl-exception-crash/subversion/bindings/javahl/native/ClientContext.cpp Thu Apr 10 20:24:08 2014
@@ -422,6 +422,7 @@ ClientContext::resolve(svn_wc_conflict_r
 {
   jobject jctx = (jobject) baton;
   JNIEnv *env = JNIUtil::getEnv();
+  *result = NULL;
 
   // Create a local frame for our references
   env->PushLocalFrame(LOCAL_FRAME_SIZE);

Modified: subversion/branches/1.7.x-javahl-exception-crash/subversion/bindings/javahl/native/JNIUtil.cpp
URL: http://svn.apache.org/viewvc/subversion/branches/1.7.x-javahl-exception-crash/subversion/bindings/javahl/native/JNIUtil.cpp?rev=1586463&r1=1586462&r2=1586463&view=diff
==============================================================================
--- subversion/branches/1.7.x-javahl-exception-crash/subversion/bindings/javahl/native/JNIUtil.cpp (original)
+++ subversion/branches/1.7.x-javahl-exception-crash/subversion/bindings/javahl/native/JNIUtil.cpp Thu Apr 10 20:24:08 2014
@@ -399,7 +399,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);
@@ -521,7 +521,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);
 }
 
@@ -621,28 +630,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.7.x-javahl-exception-crash/subversion/bindings/javahl/native/JNIUtil.h
URL: http://svn.apache.org/viewvc/subversion/branches/1.7.x-javahl-exception-crash/subversion/bindings/javahl/native/JNIUtil.h?rev=1586463&r1=1586462&r2=1586463&view=diff
==============================================================================
--- subversion/branches/1.7.x-javahl-exception-crash/subversion/bindings/javahl/native/JNIUtil.h (original)
+++ subversion/branches/1.7.x-javahl-exception-crash/subversion/bindings/javahl/native/JNIUtil.h Thu Apr 10 20:24:08 2014
@@ -138,6 +138,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);