rdtr commented on code in PR #13560: URL: https://github.com/apache/gluten/pull/13560#discussion_r4543753740
########## docs/developers/NewToGluten.md: ########## @@ -94,6 +94,46 @@ To format Java/Scala code using the [Spotless](https://github.com/diffplug/spotl ./dev/format-scala-code.sh ``` +### Java exceptions crossing native code + +JNI callbacks must call `checkException(env)` after invoking Java. It throws +`gluten::JavaException`, which owns a shared global reference to the original Java +throwable. `JNI_METHOD_END` restores that same object with JNI `Throw`, retaining Review Comment: Question. This says `JNI_METHOD_END` restores the same object, and the JNI boundary does. On the main iterator path the object is wrapped again right after. `ClosableIterator.hasNext()` and `next()` catch `Exception` and call `translateException`, and `ColumnarBatchOutIterator.translateException` returns `new GlutenException(e)` unless the message matches a schema error. https://github.com/apache/gluten/blob/bb6b836892083724ed53421c06f8813ef3c3978e/gluten-core/src/main/java/org/apache/gluten/iterator/ClosableIterator.java#L37-L38 https://github.com/apache/gluten/blob/bb6b836892083724ed53421c06f8813ef3c3978e/gluten-core/src/main/java/org/apache/gluten/iterator/ClosableIterator.java#L49-L50 https://github.com/apache/gluten/blob/bb6b836892083724ed53421c06f8813ef3c3978e/gluten-arrow/src/main/java/org/apache/gluten/vectorized/ColumnarBatchOutIterator.java#L147-L157 Code that matches on the top-level class or `SparkThrowable` sees `GlutenException`, with the original only as the cause. The tests in #13561 show the same thing. The identity checks call `hasNext0()`/`next0()` directly, and `nested native iterators retain the actual Java cause` expects `GlutenException` -> `GlutenException` -> original through `outer.hasNext()`. Neither #13561 nor #13563 touches `ClosableIterator`. Is the wrapping intended to stay? If so, I think the doc should say callers of `hasNext()`/`next()` get the original as a cause. If not, this seems like the place to stop wrapping an exception that came from a Java callback. ``` -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
