felipepessoto commented on code in PR #13560:
URL: https://github.com/apache/gluten/pull/13560#discussion_r4542372714


##########
cpp/core/jni/JavaException.cc:
##########
@@ -0,0 +1,178 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "JavaException.h"
+
+#include <glog/logging.h>
+
+#include <stdexcept>
+#include <string>
+
+namespace gluten {
+namespace {
+
+class LocalFrame {
+ public:
+  explicit LocalFrame(JNIEnv* env) : env_(env), pushed_(env->PushLocalFrame(3) 
== JNI_OK) {}

Review Comment:
   Named this `kDescriptionLocalCapacity` and documented the local-reference 
usage: the describer class and returned string need two slots, with one spare. 
The original throwable is from the enclosing frame. The capacity remains 3; 
this is a clarity change, not a change to JNI allocation behavior.



##########
cpp/core/jni/JniError.h:
##########
@@ -28,11 +28,17 @@
 #endif
 
 #ifndef JNI_METHOD_END
-#define JNI_METHOD_END(fallback_expr)                                          
  \
-  }                                                                            
  \
-  catch (std::exception & e) {                                                 
  \
-    env->ThrowNew(gluten::getJniErrorState()->glutenExceptionClass(), 
e.what()); \
-    return fallback_expr;                                                      
  \
+#define JNI_METHOD_END(fallback_expr)                                          
        \
+  }                                                                            
        \
+  catch (const gluten::JavaException& e) {                                     
        \
+    e.throwToJava(env);                                                        
        \
+    return fallback_expr;                                                      
        \
+  }                                                                            
        \
+  catch (const std::exception& e) {                                            
        \
+    if (!env->ExceptionCheck() && 
!gluten::JavaException::throwNestedToJava(env, e)) { \
+      env->ThrowNew(gluten::getJniErrorState()->glutenExceptionClass(), 
e.what());     \
+    }                                                                          
        \
+    return fallback_expr;                                                      
        \

Review Comment:
   Fixed in 9e27781a. `JNI_METHOD_END` now checks the actual pending Java 
exception after both direct and nested restoration. If none is pending, it 
attempts the existing `GlutenException` fallback; a newer pending error is left 
untouched. Failure of the fallback itself is logged.
   
   Added real-JVM tests injecting failed `Throw` calls into both paths. The two 
no-pending cases fail on the previous code and pass with the fix; separate 
cases confirm that a newer pending `OutOfMemoryError` retains its identity. All 
eight JUnit cases and eleven native regressions pass locally.



-- 
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]

Reply via email to