Skip to content

[SPARK-55755][SQL][TESTS] Handle null ArithmeticException message on JDK 25#54553

Closed
yaooqinn wants to merge 1 commit intoapache:masterfrom
yaooqinn:fix-jdk25-long-overflow
Closed

[SPARK-55755][SQL][TESTS] Handle null ArithmeticException message on JDK 25#54553
yaooqinn wants to merge 1 commit intoapache:masterfrom
yaooqinn:fix-jdk25-long-overflow

Conversation

@yaooqinn
Copy link
Member

What changes were proposed in this pull request?

On JDK 25, Math.multiplyExact/Math.addExact may throw ArithmeticException without a message (null instead of "long overflow"). This causes NullPointerException in tests that check the raw exception message via .getMessage.contains(...).

This PR:

  1. MathUtils.withOverflow: Provides a fallback message "Overflow" when the raw JDK exception message is null, preventing null propagation into Spark error conditions (both interpreted and codegen paths).
  2. Test assertions: Makes raw ArithmeticException message checks null-safe across:
    • DateExpressionsSuite (line 1825)
    • CatalystTypeConvertersSuite (line 305)
    • DateTimeUtilsSuite (line 835)
    • IntervalUtilsSuite (line 593)
    • TimestampFormatterSuite (lines 451, 453)

Why are the changes needed?

The JDK 25 scheduled CI build fails with:

java.lang.NullPointerException: Cannot invoke "String.contains(java.lang.CharSequence)" because "$org_scalatest_assert_macro_left" is null
  at DateExpressionsSuite.scala:1825

See: https://github.com/apache/spark/actions/runs/22513372344/job/65226962993

Does this PR introduce any user-facing change?

No.

How was this patch tested?

Existing tests pass on JDK 17. The MathUtils.withOverflow fix ensures non-null messages regardless of JDK version.

Was this patch authored or co-authored using generative AI tooling?

Yes, co-authored with GitHub Copilot.

…JDK 25

On JDK 25, Math.multiplyExact/addExact may throw ArithmeticException without a message (null instead of "long overflow"). This causes NPE in tests that check the raw exception message.

This PR:
1. Fixes MathUtils.withOverflow to provide a fallback message "Overflow" when the raw JDK exception message is null (both interpreted and codegen paths).
2. Makes test assertions null-safe for raw ArithmeticException message checks across DateExpressionsSuite, CatalystTypeConvertersSuite, DateTimeUtilsSuite, IntervalUtilsSuite, and TimestampFormatterSuite.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dongjoon-hyun
Copy link
Member

BTW, did you split the scope disjointly from the following PR, @yaooqinn ?

@yaooqinn
Copy link
Member Author

Oh, I didn't notice there's existing effort, just saw an error the master branch and proposed this fix. Shall I close this one? @dongjoon-hyun

@dongjoon-hyun
Copy link
Member

I'm not sure in this case because this one looks more concise. Does this make all tests pass? Could you talk with @pan3793 ?

@yaooqinn yaooqinn closed this in a7990f3 Feb 28, 2026
@yaooqinn yaooqinn deleted the fix-jdk25-long-overflow branch February 28, 2026 15:11
@yaooqinn
Copy link
Member Author

Let me merge this to fix some CI failures first, thank you @dongjoon-hyun

@dongjoon-hyun
Copy link
Member

Sounds good, @yaooqinn . Thanks.

throw ExecutionErrors.arithmeticOverflowError(e.getMessage, hint, context)
// On JDK 25+, Math.*Exact may throw ArithmeticException without a message
val message = if (e.getMessage != null) e.getMessage else "Overflow"
throw ExecutionErrors.arithmeticOverflowError(message, hint, context)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changing here causes duplication, why not do it in ExecutionErrors.arithmeticOverflowError like #54514?

in addition, better to use lower case "overflow" to match the original JDK message style

@pan3793
Copy link
Member

pan3793 commented Feb 28, 2026

@yaooqinn this change is insufficient to cover all ArithmeticException null message cases. I suggest you review #54514 in instead of hurrying to merge this one.

@pan3793
Copy link
Member

pan3793 commented Feb 28, 2026

FYI, I have a draft PR #54091 which makes all GHA pipelines pass on JDK 25. You can check each commit to evaluate the remaining issues.

@yaooqinn
Copy link
Member Author

@pan3793, my apologies, feel free to revert this one if you've gotten a better plan.

@pan3793
Copy link
Member

pan3793 commented Feb 28, 2026

Okay, reverted in 3f54ac5, JIRA is updated to "duplicate with SPARK-55714"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants