You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/05/30 16:12:37 UTC

[GitHub] [arrow] pitrou commented on a diff in pull request #13246: ARROW-16329: [Java][C++] Keep more context when marshalling errors through JNI

pitrou commented on code in PR #13246:
URL: https://github.com/apache/arrow/pull/13246#discussion_r884967137


##########
cpp/src/jni/dataset/jni_util.cc:
##########
@@ -167,9 +167,16 @@ ReservationListenableMemoryPool::~ReservationListenableMemoryPool() {}
 
 Status CheckException(JNIEnv* env) {
   if (env->ExceptionCheck()) {
-    env->ExceptionDescribe();
+    jthrowable t = env->ExceptionOccurred();
     env->ExceptionClear();
-    return Status::Invalid("Error during calling Java code from native code");
+    jclass describer_class =
+        env->FindClass("org/apache/arrow/dataset/jni/JniExceptionDescriber");
+    jmethodID describe_method = env->GetStaticMethodID(
+        describer_class, "describe", "(Ljava/lang/Throwable;)Ljava/lang/String;");
+    std::string description = JStringToCString(
+        env, (jstring)env->CallStaticObjectMethod(describer_class, describe_method, t));
+    return Status::Invalid("Error during calling Java code from native code: " +
+                           description);

Review Comment:
   Hmm... I don't know what is possible exactly, but ideally we should:
   1) map Java exception classes to specific C++ status codes (for example a `IOException` would map to `Status::IOError` while `InvalidTypeException` would map to `Status::TypeError`)
   2) keep the Java exception object in a Java-specific `StatusDetail` subclass, just like we do [for Python exceptions](https://github.com/apache/arrow/blob/master/cpp/src/arrow/python/common.cc#L54-L139)
   
   cc @lwhite1 



-- 
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-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org