You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafodion.apache.org by su...@apache.org on 2016/09/23 15:31:14 UTC

[1/5] incubator-trafodion git commit: [TRAFODION-1988] Better java exception handling in the java/JNI layer

Repository: incubator-trafodion
Updated Branches:
  refs/heads/master 951c15d01 -> 3ad30f51e


[TRAFODION-1988] Better java exception handling in the java/JNI layer

The stack trace of the exception displayed from JNI side now contains the
cause of the exception displayed in a nested way.


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

Branch: refs/heads/master
Commit: 0037eab52931483e27bcd747f362361a360a4d5a
Parents: 16ebe09
Author: selvaganesang <se...@esgyn.com>
Authored: Tue Sep 20 05:49:50 2016 +0000
Committer: selvaganesang <se...@esgyn.com>
Committed: Tue Sep 20 05:49:50 2016 +0000

----------------------------------------------------------------------
 .../tm/hbasetmlib2/javaobjectinterfacetm.cpp    | 33 ++++++++++++++------
 .../tm/hbasetmlib2/javaobjectinterfacetm.h      |  2 ++
 core/sql/executor/JavaObjectInterface.cpp       | 21 +++++++++++--
 core/sql/executor/JavaObjectInterface.h         |  2 ++
 4 files changed, 46 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/0037eab5/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 df7db02..7f7cd08 100755
--- a/core/sqf/src/seatrans/tm/hbasetmlib2/javaobjectinterfacetm.cpp
+++ b/core/sqf/src/seatrans/tm/hbasetmlib2/javaobjectinterfacetm.cpp
@@ -54,6 +54,7 @@ jclass JavaObjectInterfaceTM::gStackTraceClass = NULL;
 jmethodID JavaObjectInterfaceTM::gGetStackTraceMethodID = NULL;
 jmethodID JavaObjectInterfaceTM::gThrowableToStringMethodID = NULL;
 jmethodID JavaObjectInterfaceTM::gStackFrameToStringMethodID = NULL;
+jmethodID JavaObjectInterfaceTM::gGetCauseMethodID = NULL;
 
 //////////////////////////////////////////////////////////////////////////////
 // 
@@ -389,7 +390,7 @@ void JavaObjectInterfaceTM::logError(const char* cat, const char* file, int line
 
 bool  JavaObjectInterfaceTM::getExceptionDetails(JNIEnv *jenv)
 {
-   std::string *error_msg;
+   std::string *error_msg = NULL;
 
    if (_tlp_error_msg != NULL)
    {
@@ -421,21 +422,32 @@ bool  JavaObjectInterfaceTM::getExceptionDetails(JNIEnv *jenv)
        _tlp_error_msg = error_msg;
        return false;
    }
+
+   appendExceptionMessages(jenv, a_exception, error_msg);
+   *error_msg += "\n";
+   _tlp_error_msg = error_msg;
+   return true;
+}
+
+void JavaObjectInterfaceTM::appendExceptionMessages(JNIEnv *jenv, jthrowable a_exception, std::string *error_msg)
+{
     jstring msg_obj =
        (jstring) jenv->CallObjectMethod(a_exception,
                                          gThrowableToStringMethodID);
     const char *msg_str;
-    error_msg = new std::string("");
-    if (msg_obj != NULL) {
+    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);
     }
-    else {
+    else
        msg_str = "Exception is thrown, but tostring is null";
-       *error_msg += msg_str;
-    }
+
+
     // Get the stack trace
     jobjectArray frames =
         (jobjectArray) jenv->CallObjectMethod(
@@ -444,7 +456,7 @@ bool  JavaObjectInterfaceTM::getExceptionDetails(JNIEnv *jenv)
     if (frames == NULL)
     {
        _tlp_error_msg = error_msg;
-       return true;
+       return;
     }
     jsize frames_length = jenv->GetArrayLength(frames);
 
@@ -465,7 +477,10 @@ bool  JavaObjectInterfaceTM::getExceptionDetails(JNIEnv *jenv)
        }
     }
     *error_msg += "\n";
-    _tlp_error_msg = error_msg;
-    return true;
+    jthrowable j_cause = (jthrowable)jenv->CallObjectMethod(a_exception, gGetCauseMethodID);
+    if (j_cause != NULL) {
+       *error_msg += "Caused by ";
+       appendExceptionMessages(jenv, j_cause, error_msg);
+    }
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/0037eab5/core/sqf/src/seatrans/tm/hbasetmlib2/javaobjectinterfacetm.h
----------------------------------------------------------------------
diff --git a/core/sqf/src/seatrans/tm/hbasetmlib2/javaobjectinterfacetm.h b/core/sqf/src/seatrans/tm/hbasetmlib2/javaobjectinterfacetm.h
index 3f8d41b..f108c4d 100755
--- a/core/sqf/src/seatrans/tm/hbasetmlib2/javaobjectinterfacetm.h
+++ b/core/sqf/src/seatrans/tm/hbasetmlib2/javaobjectinterfacetm.h
@@ -142,6 +142,7 @@ public:
     return isInitialized_;
   }
   bool getExceptionDetails(JNIEnv *jenv);
+  void appendExceptionMessages(JNIEnv *jenv, jthrowable a_exception, std::string *error_msg);
   
 protected:
   static JavaVM*   jvm_;
@@ -156,6 +157,7 @@ protected:
   static jmethodID gGetStackTraceMethodID;
   static jmethodID gThrowableToStringMethodID;
   static jmethodID gStackFrameToStringMethodID;
+  static jmethodID gGetCauseMethodID;
 };
 
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/0037eab5/core/sql/executor/JavaObjectInterface.cpp
----------------------------------------------------------------------
diff --git a/core/sql/executor/JavaObjectInterface.cpp b/core/sql/executor/JavaObjectInterface.cpp
index e056ca8..beab4ed 100644
--- a/core/sql/executor/JavaObjectInterface.cpp
+++ b/core/sql/executor/JavaObjectInterface.cpp
@@ -43,6 +43,7 @@ jclass JavaObjectInterface::gStackTraceClass = NULL;
 jmethodID JavaObjectInterface::gGetStackTraceMethodID = NULL;
 jmethodID JavaObjectInterface::gThrowableToStringMethodID = NULL;
 jmethodID JavaObjectInterface::gStackFrameToStringMethodID = NULL;
+jmethodID JavaObjectInterface::gGetCauseMethodID = NULL;
 
   
 static const char* const joiErrorEnumStr[] = 
@@ -296,6 +297,9 @@ JOI_RetCode JavaObjectInterface::initJVM()
         gThrowableToStringMethodID = jenv_->GetMethodID(gThrowableClass,
                       "toString",
                       "()Ljava/lang/String;");
+        gGetCauseMethodID = jenv_->GetMethodID(gThrowableClass,
+                      "getCause",
+                      "()Ljava/lang/Throwable;");
      }
   }
   if (gStackTraceClass == NULL)
@@ -455,6 +459,14 @@ NABoolean  JavaObjectInterface::getExceptionDetails(JNIEnv *jenv)
        cli_globals->setJniErrorStr(error_msg);
        return FALSE;
    }
+   appendExceptionMessages(jenv, a_exception, error_msg);
+   error_msg += "\n";
+   cli_globals->setJniErrorStr(error_msg);
+   return TRUE;
+}
+
+void JavaObjectInterface::appendExceptionMessages(JNIEnv *jenv, jthrowable a_exception, NAString &error_msg)
+{
     jstring msg_obj =
        (jstring) jenv->CallObjectMethod(a_exception,
                                          gThrowableToStringMethodID);
@@ -480,7 +492,7 @@ NABoolean  JavaObjectInterface::getExceptionDetails(JNIEnv *jenv)
     if (frames == NULL)
     {
        cli_globals->setJniErrorStr(error_msg);
-       return TRUE;
+       return;
     }
     jsize frames_length = jenv->GetArrayLength(frames);
 
@@ -501,8 +513,11 @@ NABoolean  JavaObjectInterface::getExceptionDetails(JNIEnv *jenv)
        }
     }
     error_msg += "\n";
-    cli_globals->setJniErrorStr(error_msg);
-    return TRUE;
+    jthrowable j_cause = (jthrowable)jenv->CallObjectMethod(a_exception, gGetCauseMethodID);
+    if (j_cause != NULL) {
+       error_msg += "Caused by ";
+       appendExceptionMessages(jenv, j_cause, error_msg);
+    }
 } 
 
 NAString JavaObjectInterface::getLastError()

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/0037eab5/core/sql/executor/JavaObjectInterface.h
----------------------------------------------------------------------
diff --git a/core/sql/executor/JavaObjectInterface.h b/core/sql/executor/JavaObjectInterface.h
index 65549f0..660faa0 100644
--- a/core/sql/executor/JavaObjectInterface.h
+++ b/core/sql/executor/JavaObjectInterface.h
@@ -160,6 +160,7 @@ public:
   // Pass in jenv if the thread where the object is created is different than
   // the thread where exception occurred
   NABoolean getExceptionDetails(JNIEnv *jenv = NULL);  
+  void appendExceptionMessages(JNIEnv *jenv, jthrowable a_exception, NAString &error_msg);
   
   NAHeap *getHeap() { return heap_; }
 protected:
@@ -169,6 +170,7 @@ protected:
   static jmethodID gGetStackTraceMethodID;
   static jmethodID gThrowableToStringMethodID;
   static jmethodID gStackFrameToStringMethodID;
+  static jmethodID gGetCauseMethodID;
   static jint jniHandleCapacity_;
 
   jobject   javaObj_;


[2/5] incubator-trafodion git commit: [TRAFODION-1988] Better java exception handling in the java/JNI layer

Posted by su...@apache.org.
[TRAFODION-1988] Better java exception handling in the java/JNI layer

Fix for the check-PR failure in seabase test suite


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

Branch: refs/heads/master
Commit: 7bcae3be4b44d99a9bbe10a075dd5c53afac3e74
Parents: 0037eab
Author: selvaganesang <se...@esgyn.com>
Authored: Tue Sep 20 14:56:19 2016 +0000
Committer: selvaganesang <se...@esgyn.com>
Committed: Tue Sep 20 14:56:19 2016 +0000

----------------------------------------------------------------------
 core/sqf/src/seatrans/tm/hbasetmlib2/javaobjectinterfacetm.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/7bcae3be/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 7f7cd08..4279580 100755
--- a/core/sqf/src/seatrans/tm/hbasetmlib2/javaobjectinterfacetm.cpp
+++ b/core/sqf/src/seatrans/tm/hbasetmlib2/javaobjectinterfacetm.cpp
@@ -422,7 +422,7 @@ bool  JavaObjectInterfaceTM::getExceptionDetails(JNIEnv *jenv)
        _tlp_error_msg = error_msg;
        return false;
    }
-
+   error_msg = new std::string("");
    appendExceptionMessages(jenv, a_exception, error_msg);
    *error_msg += "\n";
    _tlp_error_msg = error_msg;


[3/5] incubator-trafodion git commit: [TRAFODION-1988] Better java exception handling in the java/JNI layer

Posted by su...@apache.org.
[TRAFODION-1988] Better java exception handling in the java/JNI layer

Fixes as per the review comments

TM exception logging was at times dumping TM core because log4cxx
infrastructure was not initialized  early in the process startup.
Initialized it as early as it can be done.


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

Branch: refs/heads/master
Commit: f509c91fcc578aac263d52d971157e9e6e1ba255
Parents: 7bcae3b
Author: selvaganesang <se...@esgyn.com>
Authored: Thu Sep 22 00:32:54 2016 +0000
Committer: selvaganesang <se...@esgyn.com>
Committed: Thu Sep 22 00:32:54 2016 +0000

----------------------------------------------------------------------
 .../tm/hbasetmlib2/javaobjectinterfacetm.cpp    | 50 ++++++++++----------
 .../tm/hbasetmlib2/javaobjectinterfacetm.h      |  2 +-
 core/sqf/src/tm/tm.cpp                          |  2 +-
 core/sqf/src/tm/tminfo.cpp                      |  2 -
 core/sqf/src/tm/tmlogging.cpp                   | 15 ++++--
 5 files changed, 38 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/f509c91f/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 4279580..23c0215 100755
--- a/core/sqf/src/seatrans/tm/hbasetmlib2/javaobjectinterfacetm.cpp
+++ b/core/sqf/src/seatrans/tm/hbasetmlib2/javaobjectinterfacetm.cpp
@@ -387,30 +387,31 @@ void JavaObjectInterfaceTM::logError(const char* cat, const char* file, int line
 {
 }
 
-
-bool  JavaObjectInterfaceTM::getExceptionDetails(JNIEnv *jenv)
+void set_error_msg(std::string &error_msg) 
 {
-   std::string *error_msg = NULL;
-
    if (_tlp_error_msg != NULL)
-   {
       delete _tlp_error_msg;
-      _tlp_error_msg = NULL;
-   }
+   _tlp_error_msg = new std::string(error_msg); 
+}
+
+
+bool  JavaObjectInterfaceTM::getExceptionDetails(JNIEnv *jenv)
+{
+   std::string error_msg;
 
    if (jenv == NULL)
        jenv = _tlp_jenv;
    if (jenv == NULL)
    {
-      error_msg = new std::string("Internal Error - Unable to obtain jenv");
-      _tlp_error_msg = error_msg;
+      error_msg = "Internal Error - Unable to obtain jenv";
+      set_error_msg(error_msg);
       return false;
    }
    if (gThrowableClass == NULL)
    {
       jenv->ExceptionDescribe();
-      error_msg = new std::string("Internal Error - Unable to find Throwable class");
-      _tlp_error_msg = error_msg;
+      error_msg = "Internal Error - Unable to find Throwable class";
+      set_error_msg(error_msg);
       return false;
    }
    jthrowable a_exception = jenv->ExceptionOccurred();
@@ -418,18 +419,18 @@ bool  JavaObjectInterfaceTM::getExceptionDetails(JNIEnv *jenv)
        jenv->ExceptionClear();
    else
    {
-       error_msg = new std::string("No java exception was thrown");
-       _tlp_error_msg = error_msg;
+       error_msg = "No java exception was thrown";
+       set_error_msg(error_msg);
        return false;
    }
-   error_msg = new std::string("");
+   error_msg = "";
    appendExceptionMessages(jenv, a_exception, error_msg);
-   *error_msg += "\n";
-   _tlp_error_msg = error_msg;
+   error_msg += "\n";
+   set_error_msg(error_msg);
    return true;
 }
 
-void JavaObjectInterfaceTM::appendExceptionMessages(JNIEnv *jenv, jthrowable a_exception, std::string *error_msg)
+void JavaObjectInterfaceTM::appendExceptionMessages(JNIEnv *jenv, jthrowable a_exception, std::string &error_msg)
 {
     jstring msg_obj =
        (jstring) jenv->CallObjectMethod(a_exception,
@@ -439,8 +440,8 @@ void JavaObjectInterfaceTM::appendExceptionMessages(JNIEnv *jenv, jthrowable a_e
     {
        msg_str = jenv->GetStringUTFChars(msg_obj, 0);
        // Start the error message in a new line
-       *error_msg = "\n";
-       *error_msg += msg_str;
+       error_msg = "\n";
+       error_msg += msg_str;
        jenv->ReleaseStringUTFChars(msg_obj, msg_str);
        jenv->DeleteLocalRef(msg_obj);
     }
@@ -454,10 +455,7 @@ void JavaObjectInterfaceTM::appendExceptionMessages(JNIEnv *jenv, jthrowable a_e
                                         a_exception,
                                         gGetStackTraceMethodID);
     if (frames == NULL)
-    {
-       _tlp_error_msg = error_msg;
        return;
-    }
     jsize frames_length = jenv->GetArrayLength(frames);
 
     jsize i = 0;
@@ -469,17 +467,17 @@ void JavaObjectInterfaceTM::appendExceptionMessages(JNIEnv *jenv, jthrowable a_e
        if (msg_obj != NULL)
        {
           msg_str = jenv->GetStringUTFChars(msg_obj, 0);
-          *error_msg += "\n";
-          *error_msg += msg_str;
+          error_msg += "\n";
+          error_msg += msg_str;
           jenv->ReleaseStringUTFChars(msg_obj, msg_str);
           jenv->DeleteLocalRef(msg_obj);
           jenv->DeleteLocalRef(frame);
        }
     }
-    *error_msg += "\n";
+    error_msg += "\n";
     jthrowable j_cause = (jthrowable)jenv->CallObjectMethod(a_exception, gGetCauseMethodID);
     if (j_cause != NULL) {
-       *error_msg += "Caused by ";
+       error_msg += "Caused by ";
        appendExceptionMessages(jenv, j_cause, error_msg);
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/f509c91f/core/sqf/src/seatrans/tm/hbasetmlib2/javaobjectinterfacetm.h
----------------------------------------------------------------------
diff --git a/core/sqf/src/seatrans/tm/hbasetmlib2/javaobjectinterfacetm.h b/core/sqf/src/seatrans/tm/hbasetmlib2/javaobjectinterfacetm.h
index f108c4d..c44013d 100755
--- a/core/sqf/src/seatrans/tm/hbasetmlib2/javaobjectinterfacetm.h
+++ b/core/sqf/src/seatrans/tm/hbasetmlib2/javaobjectinterfacetm.h
@@ -142,7 +142,7 @@ public:
     return isInitialized_;
   }
   bool getExceptionDetails(JNIEnv *jenv);
-  void appendExceptionMessages(JNIEnv *jenv, jthrowable a_exception, std::string *error_msg);
+  void appendExceptionMessages(JNIEnv *jenv, jthrowable a_exception, std::string &error_msg);
   
 protected:
   static JavaVM*   jvm_;

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/f509c91f/core/sqf/src/tm/tm.cpp
----------------------------------------------------------------------
diff --git a/core/sqf/src/tm/tm.cpp b/core/sqf/src/tm/tm.cpp
index 00db215..0414e1b 100644
--- a/core/sqf/src/tm/tm.cpp
+++ b/core/sqf/src/tm/tm.cpp
@@ -3374,13 +3374,13 @@ int main(int argc, char *argv[])
                          NULL);      // component-id
     gv_tm_info.nid (lv_my_nid);
     gv_tm_info.pid (lv_my_pid);
-
 #ifdef MULTITHREADED_TM
     XWAIT(0, -2);
 #endif
 
     msg_mon_process_startup(true); // server?
     msg_debug_hook ("tm.hook", "tm.hook");
+    tm_init_logging();
     msg_mon_tmsync_register(tm_sync_cb);
     msg_mon_enable_mon_messages (1);
     msg_enable_priority_queue();

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/f509c91f/core/sqf/src/tm/tminfo.cpp
----------------------------------------------------------------------
diff --git a/core/sqf/src/tm/tminfo.cpp b/core/sqf/src/tm/tminfo.cpp
index 4c5574d..384bae2 100644
--- a/core/sqf/src/tm/tminfo.cpp
+++ b/core/sqf/src/tm/tminfo.cpp
@@ -949,8 +949,6 @@ void TM_Info::initialize()
      }
 #endif //deug_mode       
 
-    int result = tm_init_logging();
-    TMTrace (1, ("TM DUAL logging set to %d\n", result));
     unlock();
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/f509c91f/core/sqf/src/tm/tmlogging.cpp
----------------------------------------------------------------------
diff --git a/core/sqf/src/tm/tmlogging.cpp b/core/sqf/src/tm/tmlogging.cpp
index d3ff409..f5aab90 100644
--- a/core/sqf/src/tm/tmlogging.cpp
+++ b/core/sqf/src/tm/tmlogging.cpp
@@ -28,8 +28,10 @@
 
 #include "CommonLogger.h"
 
-int gv_dual_logging =1; // Write to both SeaLog and stdout by default
+int gv_dual_logging = 1; // Write to both SeaLog and stdout by default
 static std::string TM_COMPONENT = "TM";
+static bool gv_log4cxx_initialized = false;
+
 int tm_init_logging()
 {
 	// Log4cxx logging
@@ -40,7 +42,7 @@ int tm_init_logging()
         sprintf( logNameSuffix, "_%d.log", myNid );
 
 	CommonLogger::instance().initLog4cxx("log4cxx.trafodion.tm.config",logNameSuffix);
-
+    gv_log4cxx_initialized = true;
     ms_getenv_int ("TM_DUAL_LOGGING", &gv_dual_logging);
     return gv_dual_logging; 
 }
@@ -52,6 +54,11 @@ int tm_log_write(int pv_event_type, posix_sqlog_severity_t pv_severity, char *er
     logLevel ll_severity = LL_INFO;
 
     getTMLoggingHeaderInfo(pv_severity, ll_severity, my_processName, sizeof(my_processName), my_nid, my_pid);
+    if (! gv_log4cxx_initialized) {
+       tm_log_stdout(pv_event_type, pv_severity, err_string, 0, transid, 
+          -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, exception_stack);
+       return -1;
+    }
     if (exception_stack == NULL) 
        CommonLogger::log(TM_COMPONENT, ll_severity, "Node: %d Pid: %d Name: %s TransId: %Ld Event: %d Message: %s ", 
               my_nid, my_pid, my_processName, transid, pv_event_type, err_string);
@@ -91,11 +98,13 @@ int tm_log_event(int event_id,
     int rc = 0;
     char la_buf[DTM_STRING_BUF_SIZE];
     
-    if (gv_dual_logging)
+    if (gv_dual_logging || (! gv_log4cxx_initialized))
     {   
         tm_log_stdout(event_id, severity, temp_string, error_code, -1, rmid, dtmid, seq_num, msgid, xa_error,
                       pool_size, pool_elems, msg_retries, pool_high, pool_low, pool_max, tx_state,
                       data, data1, data2, string1, node, msgid2, offset, tm_event_msg, data4);
+        if (! gv_log4cxx_initialized)
+           return -1;
     }
     char      my_processName[MS_MON_MAX_PROCESS_NAME+1];
     int       my_nid,my_pid;


[4/5] incubator-trafodion git commit: [TRAFODION-1988] Better java exception handling in the java/JNI layer

Posted by su...@apache.org.
[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 <se...@esgyn.com>
Authored: Fri Sep 23 04:21:17 2016 +0000
Committer: selvaganesang <se...@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()


[5/5] incubator-trafodion git commit: Merge [TRAFODION-1988] PR-714 Better java exception handling in the java/JNI layer

Posted by su...@apache.org.
Merge [TRAFODION-1988] PR-714 Better java exception handling in the java/JNI layer


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

Branch: refs/heads/master
Commit: 3ad30f51e8b0ad918fafe913f22ada289e3c19cf
Parents: 951c15d 7af1fd0
Author: Suresh Subbiah <su...@apache.org>
Authored: Fri Sep 23 15:30:53 2016 +0000
Committer: Suresh Subbiah <su...@apache.org>
Committed: Fri Sep 23 15:30:53 2016 +0000

----------------------------------------------------------------------
 .../tm/hbasetmlib2/javaobjectinterfacetm.cpp    | 74 ++++++++++++--------
 .../tm/hbasetmlib2/javaobjectinterfacetm.h      |  2 +
 core/sqf/src/tm/tm.cpp                          |  2 +-
 core/sqf/src/tm/tminfo.cpp                      |  2 -
 core/sqf/src/tm/tmlogging.cpp                   | 15 +++-
 core/sql/executor/JavaObjectInterface.cpp       | 32 +++++----
 core/sql/executor/JavaObjectInterface.h         |  2 +
 7 files changed, 80 insertions(+), 49 deletions(-)
----------------------------------------------------------------------