From 762c14fde587f2ff4f9b9cdaa6b2232a481edde4 Mon Sep 17 00:00:00 2001 From: Allen Byrne Date: Sun, 5 Aug 2018 11:12:39 -0500 Subject: Improve error handling of exceptions --- java/src/jni/exceptionImp.c | 5 +++ java/src/jni/h5aImp.c | 12 ++++--- java/src/jni/h5eImp.c | 8 +++-- java/src/jni/h5lImp.c | 8 +++-- java/src/jni/h5oImp.c | 87 +++++++++++++++++++++++++++------------------ 5 files changed, 77 insertions(+), 43 deletions(-) diff --git a/java/src/jni/exceptionImp.c b/java/src/jni/exceptionImp.c index afad5d5..ded632d 100644 --- a/java/src/jni/exceptionImp.c +++ b/java/src/jni/exceptionImp.c @@ -83,9 +83,14 @@ typedef struct H5E_num_t { } \ jm = ENVPTR->GetMethodID(ENVPAR jc, "", "(Ljava/lang/String;)V"); \ if (jm == NULL) { \ + printf("FATAL ERROR: GetMethodID failed\n"); \ return JNI_FALSE; \ } \ ex = ENVPTR->NewObjectA (ENVPAR jc, jm, (jvalue*)(args)); \ + if (ex == NULL) { \ + printf("FATAL ERROR: Creation failed\n"); \ + return JNI_FALSE; \ + } \ if (ENVPTR->Throw(ENVPAR (jthrowable)ex) < 0) { \ printf("FATAL ERROR: %s: Throw failed\n", (className)); \ return JNI_FALSE; \ diff --git a/java/src/jni/h5aImp.c b/java/src/jni/h5aImp.c index 13f5207..437f25f 100644 --- a/java/src/jni/h5aImp.c +++ b/java/src/jni/h5aImp.c @@ -966,7 +966,7 @@ Java_hdf_hdf5lib_H5_H5Aget_1info_1by_1idx UNPIN_JAVA_STRING(obj_name, aName); if (status < 0) { - h5libraryError(env); + h5libraryError(env); } /* end if */ else { args[0].z = ainfo.corder_valid; @@ -1002,7 +1002,7 @@ Java_hdf_hdf5lib_H5_H5Aget_1info_1by_1name UNPIN_JAVA_STRING_TWO(obj_name, aName, attr_name, attrName); if (status < 0) { - h5libraryError(env); + h5libraryError(env); } /* end if */ else { args[0].z = ainfo.corder_valid; @@ -1166,8 +1166,12 @@ H5A_iterate_cb constructor = CBENVPTR->GetMethodID(CBENVPAR cls, "", "(ZJIJ)V"); if (constructor != 0) { cb_info_t = CBENVPTR->NewObjectA(CBENVPAR cls, constructor, args); - - status = CBENVPTR->CallIntMethod(CBENVPAR visit_callback, mid, g_id, str, cb_info_t, op_data); + if (cb_info_t == NULL) { + printf("FATAL ERROR: Creation failed\n"); + } + else { + status = CBENVPTR->CallIntMethod(CBENVPAR visit_callback, mid, g_id, str, cb_info_t, op_data); + } } /* end if (constructor != 0) */ } /* end if (cls != 0) */ } /* end if (mid != 0) */ diff --git a/java/src/jni/h5eImp.c b/java/src/jni/h5eImp.c index 24ddcbc..df7e35f 100644 --- a/java/src/jni/h5eImp.c +++ b/java/src/jni/h5eImp.c @@ -508,8 +508,12 @@ H5E_walk_cb constructor = CBENVPTR->GetMethodID(CBENVPAR cls, "", "(JJJILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V"); if (constructor != 0) { cb_info_t = CBENVPTR->NewObjectA(CBENVPAR cls, constructor, args); - - status = CBENVPTR->CallIntMethod(CBENVPAR visit_callback, mid, nindx, cb_info_t, op_data); + if (cb_info_t == NULL) { + printf("FATAL ERROR: Creation failed\n"); + } + else { + status = CBENVPTR->CallIntMethod(CBENVPAR visit_callback, mid, nindx, cb_info_t, op_data); + } } /* end if (constructor != 0) */ } /* end if(cls != 0) */ } /* end if (mid != 0) */ diff --git a/java/src/jni/h5lImp.c b/java/src/jni/h5lImp.c index ac71845..7391490 100644 --- a/java/src/jni/h5lImp.c +++ b/java/src/jni/h5lImp.c @@ -574,8 +574,12 @@ H5L_iterate_cb constructor = CBENVPTR->GetMethodID(CBENVPAR cls, "", "(IZJIJ)V"); if (constructor != 0) { cb_info_t = CBENVPTR->NewObjectA(CBENVPAR cls, constructor, args); - - status = CBENVPTR->CallIntMethod(CBENVPAR visit_callback, mid, g_id, str, cb_info_t, op_data); + if (cb_info_t == NULL) { + printf("FATAL ERROR: Creation failed\n"); + } + else { + status = CBENVPTR->CallIntMethod(CBENVPAR visit_callback, mid, g_id, str, cb_info_t, op_data); + } } /* end if */ } /* end if */ } /* end if */ diff --git a/java/src/jni/h5oImp.c b/java/src/jni/h5oImp.c index 7665c70..b7bcdb6 100644 --- a/java/src/jni/h5oImp.c +++ b/java/src/jni/h5oImp.c @@ -372,41 +372,58 @@ H5O_iterate_cb constructor = CBENVPTR->GetMethodID(CBENVPAR cls, "", "(IIIIJJJJJJ)V"); if (constructor != 0) { hdrinfobuf = CBENVPTR->NewObjectA(CBENVPAR cls, constructor, args); - - args[0].j = (jlong)info->meta_size.obj.index_size; - args[1].j = (jlong)info->meta_size.obj.heap_size; - // get a reference to the H5_ih_info_t class - cls = CBENVPTR->FindClass(CBENVPAR "hdf/hdf5lib/structs/H5_ih_info_t"); - if (cls != 0) { - // get a reference to the constructor; the name is - constructor = CBENVPTR->GetMethodID(CBENVPAR cls, "", "(JJ)V"); - if (constructor != 0) { - ihinfobuf1 = CBENVPTR->NewObjectA(CBENVPAR cls, constructor, args); - args[0].j = (jlong)info->meta_size.attr.index_size; - args[1].j = (jlong)info->meta_size.attr.heap_size; - ihinfobuf2 = CBENVPTR->NewObjectA(CBENVPAR cls, constructor, args); - - args[0].j = (jlong)info->fileno; - args[1].j = (jlong)info->addr; - args[2].i = info->type; - args[3].i = (jint)info->rc; - args[4].j = (jlong)info->num_attrs; - args[5].j = info->atime; - args[6].j = info->mtime; - args[7].j = info->ctime; - args[8].j = info->btime; - args[9].l = hdrinfobuf; - args[10].l = ihinfobuf1; - args[11].l = ihinfobuf2; - // get a reference to the H5O_info_t class - cls = CBENVPTR->FindClass(CBENVPAR "hdf/hdf5lib/structs/H5O_info_t"); - if (cls != 0) { - // get a reference to the constructor; the name is - constructor = CBENVPTR->GetMethodID(CBENVPAR cls, "", "(JJIIJJJJJLhdf/hdf5lib/structs/H5O_hdr_info_t;Lhdf/hdf5lib/structs/H5_ih_info_t;Lhdf/hdf5lib/structs/H5_ih_info_t;)V"); - if (constructor != 0) { - cb_info_t = CBENVPTR->NewObjectA(CBENVPAR cls, constructor, args); - - status = CBENVPTR->CallIntMethod(CBENVPAR visit_callback, mid, g_id, str, cb_info_t, op_data); + if (ihinfobuf2 == NULL) { + printf("FATAL ERROR: Creation failed\n"); + } + else { + args[0].j = (jlong)info->meta_size.obj.index_size; + args[1].j = (jlong)info->meta_size.obj.heap_size; + // get a reference to the H5_ih_info_t class + cls = CBENVPTR->FindClass(CBENVPAR "hdf/hdf5lib/structs/H5_ih_info_t"); + if (cls != 0) { + // get a reference to the constructor; the name is + constructor = CBENVPTR->GetMethodID(CBENVPAR cls, "", "(JJ)V"); + if (constructor != 0) { + ihinfobuf1 = CBENVPTR->NewObjectA(CBENVPAR cls, constructor, args); + if (ihinfobuf1 == NULL) { + printf("FATAL ERROR: Creation failed\n"); + } + else { + args[0].j = (jlong)info->meta_size.attr.index_size; + args[1].j = (jlong)info->meta_size.attr.heap_size; + ihinfobuf2 = CBENVPTR->NewObjectA(CBENVPAR cls, constructor, args); + if (ihinfobuf2 == NULL) { + printf("FATAL ERROR: Creation failed\n"); + } + else { + args[0].j = (jlong)info->fileno; + args[1].j = (jlong)info->addr; + args[2].i = info->type; + args[3].i = (jint)info->rc; + args[4].j = (jlong)info->num_attrs; + args[5].j = info->atime; + args[6].j = info->mtime; + args[7].j = info->ctime; + args[8].j = info->btime; + args[9].l = hdrinfobuf; + args[10].l = ihinfobuf1; + args[11].l = ihinfobuf2; + // get a reference to the H5O_info_t class + cls = CBENVPTR->FindClass(CBENVPAR "hdf/hdf5lib/structs/H5O_info_t"); + if (cls != 0) { + // get a reference to the constructor; the name is + constructor = CBENVPTR->GetMethodID(CBENVPAR cls, "", "(JJIIJJJJJLhdf/hdf5lib/structs/H5O_hdr_info_t;Lhdf/hdf5lib/structs/H5_ih_info_t;Lhdf/hdf5lib/structs/H5_ih_info_t;)V"); + if (constructor != 0) { + cb_info_t = CBENVPTR->NewObjectA(CBENVPAR cls, constructor, args); + if (cb_info_t == NULL) { + printf("FATAL ERROR: Creation failed\n"); + } + else { + status = CBENVPTR->CallIntMethod(CBENVPAR visit_callback, mid, g_id, str, cb_info_t, op_data); + } + } + } + } } } } -- cgit v0.12