Skip to content

[SPARK-56092][SS] Fix NPE in StreamingQueryException.toString() when cause is null#55044

Open
xiaoxuandev wants to merge 1 commit intoapache:masterfrom
xiaoxuandev:fix-56092
Open

[SPARK-56092][SS] Fix NPE in StreamingQueryException.toString() when cause is null#55044
xiaoxuandev wants to merge 1 commit intoapache:masterfrom
xiaoxuandev:fix-56092

Conversation

@xiaoxuandev
Copy link
Contributor

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. 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:

  • 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.

… 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.
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.

1 participant