lidavidm commented on code in PR #13465: URL: https://github.com/apache/arrow/pull/13465#discussion_r911183701
########## java/c/src/main/cpp/jni_wrapper.cc: ########## @@ -162,17 +163,25 @@ void release_exported(T* base) { InnerPrivateData* private_data = reinterpret_cast<InnerPrivateData*>(base->private_data); - JNIEnvGuard guard(private_data->vm_); - JNIEnv* env = guard.env(); - - env->CallObjectMethod(private_data->j_private_data_, kPrivateDataCloseMethod); - if (env->ExceptionCheck()) { - // Can't signal this to caller, so log and then try to free things - // as best we can - env->ExceptionDescribe(); - env->ExceptionClear(); + // It is possible for the JVM to be shut down when this is called; + // guard against that. Example: Python code using JPype may shut + // down the JVM before releasing the stream. + try { + JNIEnvGuard guard(private_data->vm_); + JNIEnv* env = guard.env(); + + env->CallObjectMethod(private_data->j_private_data_, kPrivateDataCloseMethod); + if (env->ExceptionCheck()) { + // Can't signal this to caller, so log and then try to free things + // as best we can + env->ExceptionDescribe(); + env->ExceptionClear(); + } + env->DeleteGlobalRef(private_data->j_private_data_); + } catch (const JniPendingException& e) { + std::cerr << "WARNING: Failed to release Java C Data resource: " << e.what() Review Comment: No, since this isn't linked against libarrow/depends only on the ABI header and JNI. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org