Fix UnsupportedOperationException when merging ActivityOptions with i… #2749
+30
−1
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 was changed
Modified
ActivityOptions.Builder.mergeActivityOptions()to create a newArrayListwhen combining context propagators instead of callingaddAll()directly on the existing list. Added a test to verify the fix.Files changed:
temporal-sdk/src/main/java/io/temporal/activity/ActivityOptions.javatemporal-sdk/src/test/java/io/temporal/activity/ActivityOptionsTest.javaWhy?
When users set context propagators using immutable lists (e.g.,
List.of()orCollections.emptyList()), mergingActivityOptionswould throwUnsupportedOperationExceptionbecause the code attempted to calladdAll()on an immutable list.This fix follows the approach suggested by @cretz in the issue: create a new list that combines both instead of modifying one of them.
Checklist
Closes Merging ActivityOptions fails with UnsupportedOperationException when using immutable lists for context propagators #2482
How was this tested:
testActivityOptionsMergeWithImmutableContextPropagatorsthat creates twoActivityOptionswith immutable context propagator lists (Collections.emptyList()) and verifies they can be merged without throwingUnsupportedOperationExceptionActivityOptionsTesttests pass./gradlew clean build)Any docs updates needed?