Skip to content

Commit 88dea4e

Browse files
committed
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 <[email protected]>
1 parent d58da99 commit 88dea4e

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

ompi/mpi/java/c/mpi_MPI.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,23 +1124,22 @@ void ompi_java_releasePtrArray(JNIEnv *env, jlongArray array,
11241124

11251125
jboolean ompi_java_exceptionCheck(JNIEnv *env, int rc)
11261126
{
1127+
jboolean jni_exception;
1128+
11271129
if (rc < 0) {
11281130
/* handle ompi error code */
11291131
rc = ompi_errcode_get_mpi_code (rc);
11301132
/* ompi_mpi_errcode_get_class CAN NOT handle negative error codes.
11311133
* all Open MPI MPI error codes should be > 0. */
11321134
assert (rc >= 0);
11331135
}
1136+
jni_exception = (*env)->ExceptionCheck(env);
11341137

1135-
if(MPI_SUCCESS == rc)
1138+
if(MPI_SUCCESS == rc && JNI_FALSE == jni_exception)
11361139
{
11371140
return JNI_FALSE;
11381141
}
1139-
else if((*env)->ExceptionCheck(env))
1140-
{
1141-
return JNI_TRUE;
1142-
}
1143-
else
1142+
else if(MPI_SUCCESS != rc)
11441143
{
11451144
int errClass = ompi_mpi_errcode_get_class(rc);
11461145
char *message = ompi_mpi_errnum_get_string(rc);
@@ -1154,6 +1153,9 @@ jboolean ompi_java_exceptionCheck(JNIEnv *env, int rc)
11541153
(*env)->DeleteLocalRef(env, jmessage);
11551154
return JNI_TRUE;
11561155
}
1156+
else if (JNI_TRUE == jni_exception) {
1157+
return JNI_TRUE;
1158+
}
11571159
}
11581160

11591161
void* ompi_java_attrSet(JNIEnv *env, jbyteArray jval)

0 commit comments

Comments
 (0)