RPC peers: emit empty arrays for descriptor collections, never omit them#7546
Merged
jkschneider merged 4 commits intomainfrom May 1, 2026
Merged
RPC peers: emit empty arrays for descriptor collections, never omit them#7546jkschneider merged 4 commits intomainfrom
jkschneider merged 4 commits intomainfrom
Conversation
`Recipe.getDescriptor()` on the Java side always returns a descriptor whose collection-valued getters (`tags`, `options`, `preconditions`, `recipeList`, `dataTables`, `maintainers`, `contributors`, `examples`) are non-null. Callers across the ecosystem rely on that and iterate the getters without null checks. When a `RecipeDescriptor` is produced by a polyglot RPC peer, however, the JSON those peers emit can omit empty collections — Jackson then deserializes the corresponding fields as `null`, breaking every downstream caller (e.g. `descriptor.getPreconditions().iterator()`). Fix the Python and TypeScript peers to always emit every collection key, even when empty. The C# peer was already correct: `RecipeDescriptorDto` declares each list/set property with an `= []` initializer and Newtonsoft serializes empty collections as `[]`, so the JSON it produces already matches the contract. Python (`rewrite/src/rewrite/rpc/server.py`): Add `preconditions`, `maintainers`, `contributors`, `examples` as empty lists in `_recipe_descriptor_to_dict`. (The Python `RecipeDescriptor` dataclass doesn't model these fields yet, so they're hardcoded.) TypeScript (`rewrite/src/recipe.ts`): Extend the `RecipeDescriptor` interface with the four missing fields and have `Recipe.descriptor()` populate them. Updates the existing `recipe.test.ts` snapshot.
sjungling
approved these changes
May 1, 2026
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.getDescriptor()on the Java side always returns a descriptor whose collection-valued getters (tags,options,preconditions,recipeList,dataTables,maintainers,contributors,examples) are non-null. Callers across the ecosystem rely on that and iterate the getters directly:When a
RecipeDescriptorarrives from a polyglot RPC peer, the JSON that peer emits can omit empty collections — Jackson on the Java side then leaves the corresponding fieldsnull, and downstream code blows up:How
Fix at the source — each polyglot peer always emits every collection key, even when empty:
Python (
rewrite-python/rewrite/src/rewrite/rpc/server.py)_recipe_descriptor_to_dictnow emitspreconditions,maintainers,contributors,examplesas empty lists. The PythonRecipeDescriptordataclass doesn't model these fields yet, so they're hardcoded[].TypeScript (
rewrite-javascript/rewrite/src/recipe.ts)Extended the
RecipeDescriptorinterface with the four missing fields and updatedRecipe.descriptor()to populate them. Updates the existingrecipe.test.tssnapshot.C# — no change.
RecipeDescriptorDtoalready declares each list/set property with an= []initializer and Newtonsoft serializes empty collections as[], so the JSON it produces already matches the contract.Test plan
rewrite-python/rewrite/tests/rpc/test_server.py::test_recipe_descriptor_to_dict_emits_all_collection_keys— locks the contract on the Python side.rewrite-javascript/rewrite/test/recipe.test.ts— updated snapshot now asserts the four empty-collection keys.:rewrite-javascript:compileJava :rewrite-csharp:compileJava :rewrite-python:compileJavapass.