Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2491,18 +2491,15 @@ int hadoopRzOptionsSetByteBufferPool(
JNIEnv *env;
jthrowable jthr;
jobject byteBufferPool = NULL;
jobject globalByteBufferPool = NULL;
int ret;

env = getJNIEnv();
if (!env) {
errno = EINTERNAL;
return -1;
}

if (opts->byteBufferPool) {
// Delete any previous ByteBufferPool we had.
(*env)->DeleteGlobalRef(env, opts->byteBufferPool);
}

if (className) {
// Note: we don't have to call hadoopRzOptionsClearCached in this
// function, since the ByteBufferPool is passed separately from the
Expand All @@ -2512,17 +2509,35 @@ int hadoopRzOptionsSetByteBufferPool(
if (jthr) {
printExceptionAndFree(env, jthr, PRINT_EXC_ALL,
"hadoopRzOptionsSetByteBufferPool(className=%s): ", className);
errno = EINVAL;
return -1;
ret = EINVAL;
goto done;
}
opts->byteBufferPool = (*env)->NewGlobalRef(env, byteBufferPool);
if (!opts->byteBufferPool) {
printExceptionAndFree(env, jthr, PRINT_EXC_ALL,
// Only set opts->byteBufferPool if creating a global reference is
// successful
globalByteBufferPool = (*env)->NewGlobalRef(env, byteBufferPool);
if (!globalByteBufferPool) {
printPendingExceptionAndFree(env, PRINT_EXC_ALL,
"hadoopRzOptionsSetByteBufferPool(className=%s): ",
className);
errno = EINVAL;
return -1;
ret = EINVAL;
goto done;
}
// Delete any previous ByteBufferPool we had before setting a new one.
if (opts->byteBufferPool) {
(*env)->DeleteGlobalRef(env, opts->byteBufferPool);
}
opts->byteBufferPool = globalByteBufferPool;
} else if (opts->byteBufferPool) {
// If the specified className is NULL, delete any previous
// ByteBufferPool we had.
(*env)->DeleteGlobalRef(env, opts->byteBufferPool);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to also set it back to null, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah done.

}
ret = 0;
done:
destroyLocalReference(env, byteBufferPool);
if (ret) {
errno = ret;
return -1;
}
return 0;
}
Expand Down Expand Up @@ -2903,8 +2918,9 @@ hdfsGetHosts(hdfsFS fs, const char *path, tOffset start, tOffset length)
for (i = 0; i < jNumFileBlocks; ++i) {
jFileBlock =
(*env)->GetObjectArrayElement(env, jBlockLocations, i);
if ((*env)->ExceptionOccurred || !jFileBlock) {
ret = printPendingExceptionAndFree(env, PRINT_EXC_ALL,
jthr = (*env)->ExceptionOccurred(env);
if (jthr || !jFileBlock) {
ret = printExceptionAndFree(env, jthr, PRINT_EXC_ALL,
"hdfsGetHosts(path=%s, start=%"PRId64", length=%"PRId64"):"
"GetObjectArrayElement(%d)", path, start, length, i);
goto done;
Expand Down Expand Up @@ -2937,8 +2953,9 @@ hdfsGetHosts(hdfsFS fs, const char *path, tOffset start, tOffset length)
//Now parse each hostname
for (j = 0; j < jNumBlockHosts; ++j) {
jHost = (*env)->GetObjectArrayElement(env, jFileBlockHosts, j);
if ((*env)->ExceptionOccurred || jHost) {
ret = printPendingExceptionAndFree(env, PRINT_EXC_ALL,
jthr = (*env)->ExceptionOccurred(env);
if (jthr || !jHost) {
ret = printExceptionAndFree(env, jthr, PRINT_EXC_ALL,
"hdfsGetHosts(path=%s, start=%"PRId64", length=%"PRId64"): "
"NewByteArray", path, start, length);
goto done;
Expand Down Expand Up @@ -3426,8 +3443,9 @@ hdfsFileInfo* hdfsListDirectory(hdfsFS fs, const char *path, int *numEntries)
//Save path information in pathList
for (i=0; i < jPathListSize; ++i) {
tmpStat = (*env)->GetObjectArrayElement(env, jPathList, i);
if ((*env)->ExceptionOccurred || !tmpStat) {
ret = printPendingExceptionAndFree(env, PRINT_EXC_ALL,
jthr = (*env)->ExceptionOccurred(env);
if (jthr || !tmpStat) {
ret = printExceptionAndFree(env, jthr, PRINT_EXC_ALL,
"hdfsListDirectory(%s): GetObjectArrayElement(%d out of %d)",
path, i, jPathListSize);
goto done;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ void hdfsThreadDestructor(void *v)
struct ThreadLocalState *state = (struct ThreadLocalState*)v;
JNIEnv *env = state->env;;
jint ret;
jthrowable jthr;
char thr_name[MAXTHRID];

/* Detach the current thread from the JVM */
Expand All @@ -58,15 +59,17 @@ void hdfsThreadDestructor(void *v)
if (ret != 0) {
fprintf(stderr, "hdfsThreadDestructor: GetJavaVM failed with error %d\n",
ret);
if ((*env)->ExceptionOccurred) {
jthr = (*env)->ExceptionOccurred(env);
if (jthr) {
(*env)->ExceptionDescribe(env);
(*env)->ExceptionClear(env);
}
} else {
ret = (*vm)->DetachCurrentThread(vm);

if (ret != JNI_OK) {
if ((*env)->ExceptionOccurred) {
jthr = (*env)->ExceptionOccurred(env);
if (jthr) {
(*env)->ExceptionDescribe(env);
(*env)->ExceptionClear(env);
}
Expand Down