trafodion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sure...@apache.org
Subject [4/5] incubator-trafodion git commit: [TRAFODION-1988] Better java exception handling in the java/JNI layer
Date Fri, 23 Sep 2016 15:31:17 GMT
[TRAFODION-1988] Better java exception handling in the java/JNI layer

Changes to fix the regression failure


Project: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/commit/7af1fd0b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/tree/7af1fd0b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/diff/7af1fd0b

Branch: refs/heads/master
Commit: 7af1fd0bef9bdb3493d3e6c017e513c43bda7dbe
Parents: f509c91
Author: selvaganesang <selva.govindarajan@esgyn.com>
Authored: Fri Sep 23 04:21:17 2016 +0000
Committer: selvaganesang <selva.govindarajan@esgyn.com>
Committed: Fri Sep 23 04:21:17 2016 +0000

----------------------------------------------------------------------
 .../tm/hbasetmlib2/javaobjectinterfacetm.cpp         | 15 +++++++--------
 core/sql/executor/JavaObjectInterface.cpp            | 15 ++++-----------
 2 files changed, 11 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/7af1fd0b/core/sqf/src/seatrans/tm/hbasetmlib2/javaobjectinterfacetm.cpp
----------------------------------------------------------------------
diff --git a/core/sqf/src/seatrans/tm/hbasetmlib2/javaobjectinterfacetm.cpp b/core/sqf/src/seatrans/tm/hbasetmlib2/javaobjectinterfacetm.cpp
index 23c0215..8f89d8b 100755
--- a/core/sqf/src/seatrans/tm/hbasetmlib2/javaobjectinterfacetm.cpp
+++ b/core/sqf/src/seatrans/tm/hbasetmlib2/javaobjectinterfacetm.cpp
@@ -269,6 +269,9 @@ JOI_RetCode JavaObjectInterfaceTM::initJVM()
         gThrowableToStringMethodID = _tlp_jenv->GetMethodID(gThrowableClass,
                       "toString",
                       "()Ljava/lang/String;");
+        gGetCauseMethodID = _tlp_jenv->GetMethodID(gThrowableClass,
+                      "getCause",
+                      "()Ljava/lang/Throwable;");
      }
   }
   if (gStackTraceClass == NULL)
@@ -415,9 +418,7 @@ bool  JavaObjectInterfaceTM::getExceptionDetails(JNIEnv *jenv)
       return false;
    }
    jthrowable a_exception = jenv->ExceptionOccurred();
-   if (a_exception != NULL)
-       jenv->ExceptionClear();
-   else
+   if (a_exception == NULL)
    {
        error_msg = "No java exception was thrown";
        set_error_msg(error_msg);
@@ -425,8 +426,8 @@ bool  JavaObjectInterfaceTM::getExceptionDetails(JNIEnv *jenv)
    }
    error_msg = "";
    appendExceptionMessages(jenv, a_exception, error_msg);
-   error_msg += "\n";
    set_error_msg(error_msg);
+   jenv->ExceptionClear();
    return true;
 }
 
@@ -439,8 +440,6 @@ void JavaObjectInterfaceTM::appendExceptionMessages(JNIEnv *jenv, jthrowable
a_e
     if (msg_obj != NULL)
     {
        msg_str = jenv->GetStringUTFChars(msg_obj, 0);
-       // Start the error message in a new line
-       error_msg = "\n";
        error_msg += msg_str;
        jenv->ReleaseStringUTFChars(msg_obj, msg_str);
        jenv->DeleteLocalRef(msg_obj);
@@ -474,11 +473,11 @@ void JavaObjectInterfaceTM::appendExceptionMessages(JNIEnv *jenv, jthrowable
a_e
           jenv->DeleteLocalRef(frame);
        }
     }
-    error_msg += "\n";
     jthrowable j_cause = (jthrowable)jenv->CallObjectMethod(a_exception, gGetCauseMethodID);
     if (j_cause != NULL) {
-       error_msg += "Caused by ";
+       error_msg += " Caused by \n";
        appendExceptionMessages(jenv, j_cause, error_msg);
     }
+    jenv->DeleteLocalRef(a_exception);
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/7af1fd0b/core/sql/executor/JavaObjectInterface.cpp
----------------------------------------------------------------------
diff --git a/core/sql/executor/JavaObjectInterface.cpp b/core/sql/executor/JavaObjectInterface.cpp
index beab4ed..7b30ee6 100644
--- a/core/sql/executor/JavaObjectInterface.cpp
+++ b/core/sql/executor/JavaObjectInterface.cpp
@@ -451,17 +451,15 @@ NABoolean  JavaObjectInterface::getExceptionDetails(JNIEnv *jenv)
       return FALSE; 
    }
    jthrowable a_exception = jenv->ExceptionOccurred();
-   if (a_exception != NULL)
-       jenv->ExceptionClear();
-   else
+   if (a_exception == NULL)
    {
        error_msg = "No java exception was thrown";
        cli_globals->setJniErrorStr(error_msg);
        return FALSE;
    }
    appendExceptionMessages(jenv, a_exception, error_msg);
-   error_msg += "\n";
    cli_globals->setJniErrorStr(error_msg);
+   jenv->ExceptionClear();
    return TRUE;
 }
 
@@ -474,8 +472,6 @@ void JavaObjectInterface::appendExceptionMessages(JNIEnv *jenv, jthrowable
a_exc
     if (msg_obj != NULL)
     {
        msg_str = jenv->GetStringUTFChars(msg_obj, 0);
-       // Start the error message in a new line
-       error_msg = "\n";
        error_msg += msg_str;
        jenv->ReleaseStringUTFChars(msg_obj, msg_str);
        jenv->DeleteLocalRef(msg_obj);
@@ -490,10 +486,7 @@ void JavaObjectInterface::appendExceptionMessages(JNIEnv *jenv, jthrowable
a_exc
                                         a_exception,
                                         gGetStackTraceMethodID);
     if (frames == NULL)
-    {
-       cli_globals->setJniErrorStr(error_msg);
        return;
-    }
     jsize frames_length = jenv->GetArrayLength(frames);
 
     jsize i = 0;
@@ -512,12 +505,12 @@ void JavaObjectInterface::appendExceptionMessages(JNIEnv *jenv, jthrowable
a_exc
           jenv->DeleteLocalRef(frame);
        }
     }
-    error_msg += "\n";
     jthrowable j_cause = (jthrowable)jenv->CallObjectMethod(a_exception, gGetCauseMethodID);
     if (j_cause != NULL) {
-       error_msg += "Caused by ";
+       error_msg += " Caused by \n";
        appendExceptionMessages(jenv, j_cause, error_msg);
     }
+    jenv->DeleteLocalRef(a_exception);
 } 
 
 NAString JavaObjectInterface::getLastError()


Mime
View raw message