Normalize null collections in RecipeDescriptor deserialization#7545
Closed
jkschneider wants to merge 1 commit intomainfrom
Closed
Normalize null collections in RecipeDescriptor deserialization#7545jkschneider wants to merge 1 commit intomainfrom
jkschneider wants to merge 1 commit intomainfrom
Conversation
`Recipe.createRecipeDescriptor()` always passes non-null lists for `tags`, `options`, `preconditions`, `recipeList`, `dataTables`, `maintainers`, `contributors`, and `examples` — so callers in the ecosystem treat these getters as never-null and iterate them directly. When a `RecipeDescriptor` arrives from a polyglot RPC peer (rewrite-javascript-remote, rewrite-csharp-remote, rewrite-python-remote), those peers omit empty collection-valued fields from the JSON they return. Jackson's default `@AllArgsConstructor`-based deserialization then leaves the corresponding fields `null`, breaking every downstream caller that does `descriptor.getPreconditions().iterator()` without a null check. Replace the Lombok `@Value` + `@AllArgsConstructor(@JsonCreator)` setup with an explicit `@JsonCreator` constructor that normalizes null to empty collections at the deserialization boundary. Field semantics (immutability, getters, equals/hashCode, `@With`) are preserved via explicit `private final` fields plus `@Getter` / `@ToString` / `@EqualsAndHashCode`.
Member
Author
|
Withdrawing — taking a different approach. Will normalize at the per-language RPC bundle reader (NpmRecipeBundleReader / NuGetRecipeBundleReader / PipRecipeBundleReader) instead of restructuring RecipeDescriptor. |
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
Recipe.createRecipeDescriptor()always passes non-null lists fortags,options,preconditions,recipeList,dataTables,maintainers,contributors, andexamples— and callers across the ecosystem rely on that, iterating these getters without null checks.When a
RecipeDescriptoris deserialized from JSON returned by a polyglot RPC peer (rewrite-javascript-remote, rewrite-csharp-remote, rewrite-python-remote), those peers omit empty collection-valued fields. Jackson's default@AllArgsConstructor(@JsonCreator)binding then leaves those fieldsnull, and downstream code blows up:How
Replace the Lombok
@Value+@AllArgsConstructor(onConstructor = @__(@JsonCreator))with an explicit@JsonCreatorconstructor that normalizes null → empty at the deserialization boundary. Field-level immutability, getters,equals/hashCode,toString, and@Withare preserved via explicitprivate final+@Getter/@ToString/@EqualsAndHashCode.Locally constructed
RecipeDescriptors are unaffected (they were already passing non-null collections).Test plan
RecipeDescriptorTest.deserializeOmittedCollectionsAsEmptylocks the contract: a JSON document missingtags,options,preconditions,recipeList,dataTables,maintainers,contributors, andexamplesdeserializes to a descriptor whose getters return empty collections, never null.:rewrite-core:testpasses.