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


##########
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:
   `PushLocalFrame(3)` introduces a magic number whose sufficiency depends on 
the number of local refs created in `describe(...)` (and future changes). 
Making this a named constant and/or using a more conservative capacity (with a 
short comment explaining the expected local-ref usage) will reduce the chance 
of accidental regressions when `describe(...)` evolves.



##########
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:
   If `e.throwToJava(env)` fails to set a pending Java exception (e.g., 
`env->Throw(...)` returns `JNI_ERR`), the macro returns to Java with *no 
exception pending*, which can lead to silent failure. Same risk exists if a 
nested carrier claims success but `Throw` fails. Recommendation: after 
attempting to restore the throwable, verify `env->ExceptionCheck()`; if not 
pending, fall back to `ThrowNew(..., e.what())` (or have 
`throwToJava`/`throwNestedToJava` return a success flag and only skip the 
fallback when a Java exception is actually pending).



##########
gluten-arrow/pom.xml:
##########
@@ -278,4 +278,47 @@
     
<testOutputDirectory>target/scala-${scala.binary.version}/test-classes</testOutputDirectory>
   </build>
 
+  <profiles>
+    <profile>
+      <id>exclude-jni-test</id>
+      <activation>
+        <activeByDefault>true</activeByDefault>
+      </activation>
+      <build>
+        <plugins>
+          <plugin>
+            <groupId>org.apache.maven.plugins</groupId>
+            <artifactId>maven-surefire-plugin</artifactId>
+            <configuration>
+              <excludes combine.children="append">
+                <!-- The jni-test profile requires the separately built native 
test bridge. -->
+                <exclude>**/JavaExceptionJniTest.java</exclude>
+              </excludes>
+            </configuration>
+          </plugin>
+        </plugins>
+      </build>
+    </profile>
+    <profile>
+      <id>jni-test</id>
+      <properties>
+        
<gluten.jni.test.lib.dir>${project.basedir}/../cpp/build/test-libs</gluten.jni.test.lib.dir>
+      </properties>
+      <build>
+        <plugins>
+          <plugin>
+            <groupId>org.apache.maven.plugins</groupId>
+            <artifactId>maven-surefire-plugin</artifactId>
+            <configuration>
+              <failIfNoTests>true</failIfNoTests>
+              <forkedProcessTimeoutInSeconds>60</forkedProcessTimeoutInSeconds>
+              <systemPropertyVariables>
+                
<gluten.jni.test.lib.dir>${gluten.jni.test.lib.dir}</gluten.jni.test.lib.dir>
+              </systemPropertyVariables>
+            </configuration>
+          </plugin>
+        </plugins>
+      </build>
+    </profile>
+  </profiles>

Review Comment:
   `exclude-jni-test` is `activeByDefault`, which Maven deactivates as soon as 
*any* other profile becomes active (common in this repo’s builds, e.g. 
`-Pspark-3.5 -Pbackends-velox -Pjava-17`). That can make `JavaExceptionJniTest` 
run unintentionally in non-JNI builds and fail on missing native bridge. 
Consider moving the exclusion into the default surefire config (outside 
profiles) and having `jni-test` explicitly override/remove the exclusion, or 
gate the test with an explicit `gluten.jni.test.enabled` system property (set 
only by the `jni-test` profile) so normal profile-heavy builds don’t 
accidentally execute it.



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