Fix Issue #997: Preserve ConfigEntry order during merge operations#1296
Fix Issue #997: Preserve ConfigEntry order during merge operations#1296ravisastryk wants to merge 2 commits into
Conversation
…ng merge operations The merge() method was reversing entry order by inserting at position 0. Fixed by collecting entries first and using addAll(0, collection) which preserves iteration order.
drivenflywheel
left a comment
There was a problem hiding this comment.
Code and tests look good. Will have to evaluate downstream impacts prior to downstream integration in case any existing configs deliberately leverage the existing behavior. Those downstream configs could be reworked, but they'll need to be identified.
|
Directly modifying the behavior of the merge method like this seems potentially dangerous because of possible downstream effects. I think a safer alternative is to create a new overloaded |
That's a good point. However, if downstream systems are affected, they were relying on buggy behavior and need fixing anyway and we never documented this behavior and it is actually fixing the original bug #997 |
|
Thank you @rupert-griffin @drivenflywheel for reviewing my PR. When you get a chance, please re-review. I updated test to make it clear. Thank you for your time and consideration. |
|
@rupert-griffin @drivenflywheel Could you please review again? Thank you |
|
@rupert-griffin @jpdahlke @drivenflywheel Can you please re-review? |
|
@ravisastryk - I understand that you're eager to get this merged, but it's not likely to happen in the near term. This PR changes heavily-leveraged behavior that's been in place for years - and in a good way - but once this is merged downstream integrators won't be able to accept any other emissary changes unless they also ensure that this change won't impact their runtime behavior. That can be a heavy lift, and we don't want this change to impede any urgent needs that may come up. |
Thank you for the thoughtful explanation @drivenflywheel I appreciate the transparency about the downstream concerns and the care taken to protect integrators from unexpected disruptions. That said, I'd love to keep this conversation going so we can find a path forward when the timing is right. A few thoughts that might help frame that discussion:
No pressure on timing. I just want to make sure the fix for #997 stays on the radar and that there's a clear path to eventually landing it. Happy to take direction on whichever approach the team prefers. |
The
merge()method was reversing entry order by inserting at position 0. Fixed by collecting entries first and using addAll(0, collection) which preserves iteration order.Fixes #997 - ConfigEntry order is now preserved during merge operations.
Background and Context
When merging configurations, entries were inserted at position 0 individually. This was causing the final order to be reversed from the source file order.
[valueA, valueB, valueC][valueC, valueB, valueA]Why This Works
List.addAll(int index, Collection c)inserts all elements in iteration order starting at the specified index. The existing elements shift right to accommodate.Why This Is Better
add(0, x)in loopaddAll(0, collection)Fix
Replace the loop of
add(0, entry)calls with a singleaddAll(0, entries)which preserves iteration order while still placing merged entries at the front.Changes
ServiceConfigGuide.merge(): UseaddAll(0, ...)instead of individual insertionsTests