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

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


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

commit d5caaaa3437b29ae7d2253b4c4a05f4b87952eb9
Author: Xi Chen <[email protected]>
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 <[email protected]>
    Signed-off-by: Wenchen Fan <[email protected]>
    (cherry picked from commit cef3c86e046edb43beb487e92f0542b5d8354be4)
    Signed-off-by: Wenchen Fan <[email protected]>
---
 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 0f329b5655b3..2331a8e67b28 100644
--- a/common/utils/src/main/scala/org/apache/spark/SparkThrowableHelper.scala
+++ b/common/utils/src/main/scala/org/apache/spark/SparkThrowableHelper.scala
@@ -61,7 +61,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 299bcea3f9e2..a5f5eb21c68b 100644
--- a/core/src/test/scala/org/apache/spark/SparkThrowableSuite.scala
+++ b/core/src/test/scala/org/apache/spark/SparkThrowableSuite.scala
@@ -416,6 +416,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
@@ -432,6 +433,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: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to