Fix Row.toString NPE on a null nested inside an array, map or row - #39587
Open
PDGGK wants to merge 1 commit into
Open
Fix Row.toString NPE on a null nested inside an array, map or row#39587PDGGK wants to merge 1 commit into
PDGGK wants to merge 1 commit into
Conversation
toPrettyRowString drops a row's own null fields, but every recursive call hands the raw element to toPrettyFieldValueString, which dereferences it: a null String hits string.replace, a null Row hits row.getValues, and a null array or map hits value.getClass. Only the numeric and boolean branches survive, because Objects.toString already renders null as "null". Return "null" for a null value instead, which is what those numeric branches have always produced. Row.toString has routed through this printer since 2.69.0, so the NPE fires from logging, PAssert messages and debugger inspection - usually while a pipeline is already reporting a different problem. Fixes apache#21063
Contributor
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
Contributor
Author
|
assign set of reviewers |
Contributor
|
Assigning reviewers: R: @ahmedabu98 for label java. Note: If you would like to opt out of this review, comment Available commands:
The PR bot will only process comments in the main thread (not review comments). |
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.
Row.toString()throwsNullPointerExceptionwhenever a null sits inside an array, an iterable, a map or a nested row.toPrettyRowStringskips a row's own null fields, but every recursive call hands the raw element totoPrettyFieldValueString, which has no null check and dereferences it —string.replaceforSTRING,row.getValues()forROW,value.getClass()forARRAY/MAP. Only the numeric and boolean branches survive, and only becauseObjects.toStringalready renders a null as"null".These values are legal:
RowUtilsexplicitly accepts null array elements and null map values when the element type is nullable.The fix
Return
"null"for a null value at the top oftoPrettyFieldValueString. That is not a new rendering — it is exactly what the numeric branches have always produced, so this makes the remaining types consistent with the ones that already worked. Seven lines, one file, no API or wire-format change.toPrettyRowString's deliberate skipping of top-level null fields is left alone; that is the printer's intended terse style.Why this regressed
Row.toString()used to calltoString(true), whose private helper opens withif (value == null) { return "<null>"; }and is therefore null-safe at every depth. That method is still present.Row.toString()was rerouted toSchemaUtils.toPrettyString(this)in #35150, andSchemaUtils.toPrettyString(this)first appears inRow.javaatv2.69.0— it is absent fromv2.67.0andv2.68.0— so every release from 2.69.0 on has it.toString()is called from logging,PAssertfailure messages, exception messages and debugger inspection, so in practice the NPE fires while a pipeline is already reporting a different problem, and hides it.SchemaUtilsTestis 107 lines and does not reference the pretty-printer at all, which is why the 279 lines added in #35150 went unnoticed.Testing
Four tests added to
SchemaUtilsTest: null inside an array of strings, a null map value, a null row inside an array, and — as a control that pins the existing behaviour — null inside an array of ints. The first three fail on currentmasterwith the NPEs above and pass with this change; the control passes both before and after, which is what makes the"null"rendering a consistency fix rather than a new choice.:sdks:java:core:test --tests "org.apache.beam.sdk.schemas.*Test"with--rerun-tasks— 522 tests, 0 failures, 0 errors:sdks:java:core:spotlessJavaCheck— passesFixes #21063