Skip to content

[SPARK-55714][SQL] JDK might throw ArithmeticException without message#54514

Open
pan3793 wants to merge 1 commit intoapache:masterfrom
pan3793:SPARK-55714
Open

[SPARK-55714][SQL] JDK might throw ArithmeticException without message#54514
pan3793 wants to merge 1 commit intoapache:masterfrom
pan3793:SPARK-55714

Conversation

@pan3793
Copy link
Member

@pan3793 pan3793 commented Feb 26, 2026

What changes were proposed in this pull request?

Canonicalize the error message of SparkArithmeticException:

  • null => "overflow"
  • "byte overflow", "long overflow", etc., to "overflow".
  • leave others as-is.

Update tests to accept null message from ArithmeticException

Why are the changes needed?

During test, I found JDK 25 might throw ArithmeticException with null message, and it varies on different platforms / CPU models, for example, it's different on Apple M1 and x86 Server, and even different on Intel Skylake and AMD Zen4 (both are x86 but with different instructions support)

https://bugs.openjdk.org/browse/JDK-8367990

This is expected behavior. For "hot throws", the JIT will produce compiled code that does not go through the interpreter via deoptimization to throw an exception but throws a pre-allocated exception object without a stack trace or message. ... this optimization can be disabled with -XX:-OmitStackTraceInFastThrow.

Does this PR introduce any user-facing change?

Some ARITHMETIC_OVERFLOW error condition message changes from "byte overflow", "long overflow", etc., to "overflow".

How was this patch tested?

Pass GHA for JDK 17. JDK 25 will be covered by daily tests.

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

No, the patch is crafted by hand.

@pan3793 pan3793 changed the title [SPARK-55714][SQL] JDK 25 might throw ArithmeticException without message [SPARK-55714][SQL] JDK might throw ArithmeticException without message Feb 26, 2026
@pan3793 pan3793 requested review from MaxGekk and cloud-fan February 26, 2026 12:12
case null => "overflow"
case m if m.contains("overflow") => "overflow"
case m => m
}
Copy link
Member

Choose a reason for hiding this comment

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

Can we use a simple Scala-style one-liner?

-    val canonicalMessage = message match {
-      // For "hot throws", the JIT will produce compiled code that does not
-      // go through the interpreter via deoptimization to throw an exception
-      // but throws a pre-allocated exception object without a stack trace
-      // or message. See https://bugs.openjdk.org/browse/JDK-8367990
-      case null => "overflow"
-      case m if m.contains("overflow") => "overflow"
-      case m => m
-    }
+    val canonicalMessage = Option(message).filterNot(_.contains("overflow")).getOrElse("overflow")

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.

2 participants