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


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

Review Comment:
   Using an `activeByDefault` profile to exclude the JNI test is brittle 
because Maven disables `activeByDefault` profiles as soon as any other profile 
is explicitly activated (common in this repo via `-Pbackends-velox`, 
`-Pspark-*`, `-Pjava-*`, etc.). That can cause `JavaExceptionJniTest` to run 
unexpectedly (without the native bridge configured) and fail the module 
build.\n\nRecommendation (mandatory): make the exclusion unconditional in the 
default surefire config (outside profiles), and have `jni-test` *explicitly* 
opt-in to running the test (e.g., via surefire `includes` / groups) or activate 
`jni-test` based on presence of `gluten.jni.test.lib.dir` and keep the default 
exclusion always-on unless that property is set.



##########
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 (std::exception & e) {                                                 
        \
+    if (!env->ExceptionCheck() && 
!gluten::JavaException::throwNestedToJava(env, e)) { \
+      env->ThrowNew(gluten::getJniErrorState()->glutenExceptionClass(), 
e.what());     \
+    }                                                                          
        \
+    return fallback_expr;                                                      
        \
   }

Review Comment:
   `catch (std::exception & e)` should be `catch (const std::exception& e)`. 
Catching by non-const reference can fail to match exceptions thrown as `const 
std::exception` (or derived) and also suggests mutation of the exception 
object. Updating this improves correctness and aligns with typical exception 
handling conventions.



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