Skip to content

Commit

Permalink
[SPARK-49480][CORE] Fix NullPointerException from `SparkThrowableHelp…
Browse files Browse the repository at this point in the history
…er.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 apache#47946 from jshmchenxi/SPARK-49480/null-pointer-is-internal-error.

Authored-by: Xi Chen <[email protected]>
Signed-off-by: Wenchen Fan <[email protected]>
  • Loading branch information
jshmchenxi authored and cloud-fan committed Sep 2, 2024
1 parent dc82285 commit cef3c86
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit cef3c86

Please sign in to comment.