This is an automated email from the ASF dual-hosted git repository.

wenchen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git


The following commit(s) were added to refs/heads/master by this push:
     new cef3c86e046e [SPARK-49480][CORE] Fix NullPointerException from 
`SparkThrowableHelper.isInternalError`
cef3c86e046e is described below

commit cef3c86e046edb43beb487e92f0542b5d8354be4
Author: Xi Chen <jshmche...@gmail.com>
AuthorDate: Mon Sep 2 13:58:18 2024 +0800

    [SPARK-49480][CORE] Fix NullPointerException from 
`SparkThrowableHelper.isInternalError`
    
    ### What changes were proposed in this pull request?
    
    Handle null input for `SparkThrowableHelper.isInternalError` method.
    
    ### Why are the changes needed?
    
    The `SparkThrowableHelper.isInternalError` method doesn't handle null 
input, and it could lead to NullPointerException. It happens when a 
`SparkException` without `errorClass` is invoked `isInternalError`.
    
    ### Does this PR introduce _any_ user-facing change?
    
    No
    
    ### How was this patch tested?
    
    Add 2 assertions to current test cases to cover this issue.
    
    ### Was this patch authored or co-authored using generative AI tooling?
    
    No
    
    Closes #47946 from jshmchenxi/SPARK-49480/null-pointer-is-internal-error.
    
    Authored-by: Xi Chen <jshmche...@gmail.com>
    Signed-off-by: Wenchen Fan <wenc...@databricks.com>
---
 common/utils/src/main/scala/org/apache/spark/SparkThrowableHelper.scala | 2 +-
 core/src/test/scala/org/apache/spark/SparkThrowableSuite.scala          | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git 
a/common/utils/src/main/scala/org/apache/spark/SparkThrowableHelper.scala 
b/common/utils/src/main/scala/org/apache/spark/SparkThrowableHelper.scala
index db5eff72e124..428c9d2a4935 100644
--- a/common/utils/src/main/scala/org/apache/spark/SparkThrowableHelper.scala
+++ b/common/utils/src/main/scala/org/apache/spark/SparkThrowableHelper.scala
@@ -74,7 +74,7 @@ private[spark] object SparkThrowableHelper {
   }
 
   def isInternalError(errorClass: String): Boolean = {
-    errorClass.startsWith("INTERNAL_ERROR")
+    errorClass != null && errorClass.startsWith("INTERNAL_ERROR")
   }
 
   def getMessage(e: SparkThrowable with Throwable, format: 
ErrorMessageFormat.Value): String = {
diff --git a/core/src/test/scala/org/apache/spark/SparkThrowableSuite.scala 
b/core/src/test/scala/org/apache/spark/SparkThrowableSuite.scala
index 0c22edbe984c..d99589c171c3 100644
--- a/core/src/test/scala/org/apache/spark/SparkThrowableSuite.scala
+++ b/core/src/test/scala/org/apache/spark/SparkThrowableSuite.scala
@@ -259,6 +259,7 @@ class SparkThrowableSuite extends SparkFunSuite {
     } catch {
       case e: SparkThrowable =>
         assert(e.getErrorClass == null)
+        assert(!e.isInternalError)
         assert(e.getSqlState == null)
       case _: Throwable =>
         // Should not end up here
@@ -275,6 +276,7 @@ class SparkThrowableSuite extends SparkFunSuite {
     } catch {
       case e: SparkThrowable =>
         assert(e.getErrorClass == "CANNOT_PARSE_DECIMAL")
+        assert(!e.isInternalError)
         assert(e.getSqlState == "22018")
       case _: Throwable =>
         // Should not end up here


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@spark.apache.org
For additional commands, e-mail: commits-h...@spark.apache.org

Reply via email to