[SPARK-56092][SS] Fix NPE in StreamingQueryException.toString() when cause is null#55044
Open
xiaoxuandev wants to merge 1 commit intoapache:masterfrom
Open
[SPARK-56092][SS] Fix NPE in StreamingQueryException.toString() when cause is null#55044xiaoxuandev wants to merge 1 commit intoapache:masterfrom
xiaoxuandev wants to merge 1 commit intoapache:masterfrom
Conversation
… toString ### What changes were proposed in this pull request? Add null safety to StreamingQueryException.toString() to handle cases where cause is null or cause.getMessage is null. Changes: - StreamingQueryException.toString(): use Option to guard against both null cause and null cause.getMessage, falling back to message field. - New StreamingQueryExceptionSuite with tests for null cause, normal cause, and cause with null message. ### Why are the changes needed? In Spark Connect, GrpcExceptionConverter constructs StreamingQueryException with params.cause.orNull, which passes null when the original cause is unavailable during gRPC deserialization. Calling toString() on such an instance throws NPE because the original code calls cause.getMessage unconditionally. ### Does this PR introduce _any_ user-facing change? No. This is a bug fix that prevents an NPE when printing a StreamingQueryException with a null cause. ### How was this patch tested? New unit tests in StreamingQueryExceptionSuite covering three scenarios: - cause is null - cause is non-null with a message - cause is non-null but getMessage returns null ### Was this patch authored or co-authored using generative AI tooling? Yes, co-authored with Kiro.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
Add null safety to StreamingQueryException.toString() to handle cases where cause is null or cause.getMessage is null.
Changes:
Why are the changes needed?
In Spark Connect, GrpcExceptionConverter constructs StreamingQueryException with params.cause.orNull, which passes null when the original cause is unavailable during gRPC deserialization. Calling toString() on such an instance throws NPE because the original code calls cause.getMessage unconditionally.
Does this PR introduce any user-facing change?
No. Before this fix, calling toString() on a StreamingQueryException with a null cause (e.g. from Spark Connect) would throw an NPE, hiding the actual error message. After this fix, it correctly displays the exception message instead.
How was this patch tested?
New unit tests in StreamingQueryExceptionSuite covering three scenarios:
Was this patch authored or co-authored using generative AI tooling?
Yes, co-authored with Kiro.