Skip to content

Do not mutate the input map in switch closure/transformer factories#700

Merged
garydgregory merged 2 commits into
apache:masterfrom
rootvector2:switch-factory-input-map-copy
Jul 2, 2026
Merged

Do not mutate the input map in switch closure/transformer factories#700
garydgregory merged 2 commits into
apache:masterfrom
rootvector2:switch-factory-input-map-copy

Conversation

@rootvector2

Copy link
Copy Markdown
Contributor

switchClosure(Map), switchMapClosure(Map) and switchMapTransformer(Map) pulled the default out with map.remove(null) on the caller's map, so the null-key entry vanished from the caller's map as a side effect; spotted while extending the sibling fix in #696 that only touched SwitchTransformer.switchTransformer, they now copy into a LinkedHashMap first.

@garydgregory

Copy link
Copy Markdown
Member

Hello @rootvector2
Thank you for the PR.

Please update the tests here and the new one from #696 to also make sure the result from calling the various switch*() is valid.

Even though we might have other tests that do so, seeing a simple check in these new tests give me more confidence that there are no unintended side-effects.

TY!

Signed-off-by: Naveed Khan <dxbnaveed.k@gmail.com>
@rootvector2

Copy link
Copy Markdown
Contributor Author

Done. Each test now executes the built switch*() result and checks it routes the match and the default correctly, and I added the same check to the switchTransformer test from #696.

@garydgregory garydgregory merged commit dbf599d into apache:master Jul 2, 2026
10 checks passed
@garydgregory garydgregory changed the title do not mutate the input map in switch closure/transformer factories Do not mutate the input map in switch closure/transformer factories Jul 2, 2026
garydgregory added a commit that referenced this pull request Jul 2, 2026
ClosureUtils.switchMapClosure and TransformerUtils.switchMapTransformer
(#700).
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.

2 participants