From c50b8fcb023bba882152a8344621a82b49f2c3f6 Mon Sep 17 00:00:00 2001 From: Nathaniel Graham Date: Sun, 19 Jun 2016 17:49:45 +0200 Subject: [PATCH 1/2] Java bindings exception handling fix Fixed an error where if there were no MPI exceptions, a JNI error could still exist and not get handled. Signed-off-by: Nathaniel Graham --- ompi/mpi/java/c/mpi_MPI.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/ompi/mpi/java/c/mpi_MPI.c b/ompi/mpi/java/c/mpi_MPI.c index ee6984760f..e11ea9c73e 100644 --- a/ompi/mpi/java/c/mpi_MPI.c +++ b/ompi/mpi/java/c/mpi_MPI.c @@ -1128,6 +1128,8 @@ void ompi_java_releasePtrArray(JNIEnv *env, jlongArray array, jboolean ompi_java_exceptionCheck(JNIEnv *env, int rc) { + jboolean jni_exception; + if (rc < 0) { /* handle ompi error code */ rc = ompi_errcode_get_mpi_code (rc); @@ -1135,16 +1137,13 @@ jboolean ompi_java_exceptionCheck(JNIEnv *env, int rc) * all Open MPI MPI error codes should be > 0. */ assert (rc >= 0); } + jni_exception = (*env)->ExceptionCheck(env); - if(MPI_SUCCESS == rc) + if(MPI_SUCCESS == rc && JNI_FALSE == jni_exception) { return JNI_FALSE; } - else if((*env)->ExceptionCheck(env)) - { - return JNI_TRUE; - } - else + else if(MPI_SUCCESS != rc) { int errClass = ompi_mpi_errcode_get_class(rc); char *message = ompi_mpi_errnum_get_string(rc); @@ -1158,6 +1157,9 @@ jboolean ompi_java_exceptionCheck(JNIEnv *env, int rc) (*env)->DeleteLocalRef(env, jmessage); return JNI_TRUE; } + else if (JNI_TRUE == jni_exception) { + return JNI_TRUE; + } } void* ompi_java_attrSet(JNIEnv *env, jbyteArray jval) From a7bc948b29cb5edbef7e125e784330aad89a0b9f Mon Sep 17 00:00:00 2001 From: Nathaniel Graham Date: Thu, 23 Jun 2016 15:09:07 +0200 Subject: [PATCH 2/2] Fix Java Coverity issue Fixing a possible error that Coverity pointed out in ompi_java_exceptionCheck. Signed-off-by: Nathaniel Graham --- ompi/mpi/java/c/mpi_MPI.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ompi/mpi/java/c/mpi_MPI.c b/ompi/mpi/java/c/mpi_MPI.c index e11ea9c73e..3ad7296591 100644 --- a/ompi/mpi/java/c/mpi_MPI.c +++ b/ompi/mpi/java/c/mpi_MPI.c @@ -1157,9 +1157,8 @@ jboolean ompi_java_exceptionCheck(JNIEnv *env, int rc) (*env)->DeleteLocalRef(env, jmessage); return JNI_TRUE; } - else if (JNI_TRUE == jni_exception) { - return JNI_TRUE; - } + /* If we get here, a JNI error has occurred. */ + return JNI_TRUE; } void* ompi_java_attrSet(JNIEnv *env, jbyteArray jval)