Skip to content
Snippets Groups Projects
Commit ce82f9bd authored by brinn's avatar brinn
Browse files

change: throw IndexOutOfBoundsException (rather than IllegalArgumentException)...

change: throw IndexOutOfBoundsException (rather than IllegalArgumentException) when an index is out-of-bounds

SVN: 19753
parent def7809d
No related branches found
No related tags found
No related merge requests found
...@@ -39,6 +39,7 @@ extern "C" { ...@@ -39,6 +39,7 @@ extern "C" {
extern jboolean h5JNIFatalError( JNIEnv *env, char *functName); extern jboolean h5JNIFatalError( JNIEnv *env, char *functName);
extern jboolean h5nullArgument( JNIEnv *env, char *functName); extern jboolean h5nullArgument( JNIEnv *env, char *functName);
extern jboolean h5badArgument( JNIEnv *env, char *functName); extern jboolean h5badArgument( JNIEnv *env, char *functName);
extern jboolean h5indexOutOfBounds( JNIEnv *env, char *functName);
/* Change byte order for data type of length 2. */ /* Change byte order for data type of length 2. */
#define CHANGE_BYTE_ORDER_2(ARRAY) {jbyte _tmp; _tmp=ARRAY[0]; ARRAY[0]=ARRAY[1]; ARRAY[1]=_tmp;} #define CHANGE_BYTE_ORDER_2(ARRAY) {jbyte _tmp; _tmp=ARRAY[0]; ARRAY[0]=ARRAY[1]; ARRAY[1]=_tmp;}
...@@ -97,7 +98,7 @@ JNIEXPORT void JNICALL FUNCTIONNAMETB ...@@ -97,7 +98,7 @@ JNIEXPORT void JNICALL FUNCTIONNAMETB
inSize = (*env)->GetArrayLength(env, inData); inSize = (*env)->GetArrayLength(env, inData);
#endif #endif
if ((inStart < 0) || (inStart + len > inSize)) { if ((inStart < 0) || (inStart + len > inSize)) {
h5badArgument(env, OOB_IN_ERR_TB); h5indexOutOfBounds(env, OOB_IN_ERR_TB);
return; return;
} }
...@@ -107,7 +108,7 @@ JNIEXPORT void JNICALL FUNCTIONNAMETB ...@@ -107,7 +108,7 @@ JNIEXPORT void JNICALL FUNCTIONNAMETB
outSize = (*env)->GetArrayLength(env, outData); outSize = (*env)->GetArrayLength(env, outData);
#endif #endif
if ((outStart < 0) || (outStart + lenInBytes > outSize)) { if ((outStart < 0) || (outStart + lenInBytes > outSize)) {
h5badArgument(env, OOB_OUT_ERR_TB); h5indexOutOfBounds(env, OOB_OUT_ERR_TB);
return; return;
} }
...@@ -185,7 +186,7 @@ JNIEXPORT void JNICALL FUNCTIONNAMEBT ...@@ -185,7 +186,7 @@ JNIEXPORT void JNICALL FUNCTIONNAMEBT
inSize = (*env)->GetArrayLength(env, inData); inSize = (*env)->GetArrayLength(env, inData);
#endif #endif
if ((inStart < 0) || (inStart + lenInBytes > inSize)) { if ((inStart < 0) || (inStart + lenInBytes > inSize)) {
h5badArgument(env, OOB_IN_ERR_BT); h5indexOutOfBounds(env, OOB_IN_ERR_BT);
return; return;
} }
...@@ -195,7 +196,7 @@ JNIEXPORT void JNICALL FUNCTIONNAMEBT ...@@ -195,7 +196,7 @@ JNIEXPORT void JNICALL FUNCTIONNAMEBT
outSize = (*env)->GetArrayLength(env, outData); outSize = (*env)->GetArrayLength(env, outData);
#endif #endif
if ((outStart < 0) || (outStart + len > outSize)) { if ((outStart < 0) || (outStart + len > outSize)) {
h5badArgument(env, OOB_OUT_ERR_BT); h5indexOutOfBounds(env, OOB_OUT_ERR_BT);
return; return;
} }
......
...@@ -206,6 +206,63 @@ jboolean h5badArgument( JNIEnv *env, char *functName) ...@@ -206,6 +206,63 @@ jboolean h5badArgument( JNIEnv *env, char *functName)
return JNI_TRUE; return JNI_TRUE;
} }
/*
* An Index-out-of-bounds error argument in an HDF5 call
* Create and throw an 'IllegalArgumentException'
*
* Note: This routine never returns from the 'throw',
* and the Java native method immediately raises the
* exception.
*/
jboolean h5indexOutOfBounds( JNIEnv *env, char *functName)
{
jmethodID jm;
jclass jc;
char * args[2];
jobject ex;
jstring str;
int rval;
#ifdef __cplusplus
jc = env->FindClass("java/lang/IndexOutOfBoundsException");
#else
jc = (*env)->FindClass(env, "java/lang/IndexOutOfBoundsException");
#endif
if (jc == NULL) {
return JNI_FALSE;
}
#ifdef __cplusplus
jm = env->GetMethodID(jc, "<init>", "(Ljava/lang/String;)V");
#else
jm = (*env)->GetMethodID(env, jc, "<init>", "(Ljava/lang/String;)V");
#endif
if (jm == NULL) {
return JNI_FALSE;
}
#ifdef __cplusplus
str = env->NewStringUTF(functName);
#else
str = (*env)->NewStringUTF(env,functName);
#endif
args[0] = (char *)str;
args[1] = 0;
#ifdef __cplusplus
ex = env->NewObjectA ( jc, jm, (jvalue *)args );
rval = env->Throw((jthrowable) ex );
#else
ex = (*env)->NewObjectA ( env, jc, jm, (jvalue *)args );
rval = (*env)->Throw(env, ex );
#endif
if (rval < 0) {
fprintf(stderr, "FATAL ERROR: BadArgument: Throw failed\n");
return JNI_FALSE;
}
return JNI_TRUE;
}
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment