-
Notifications
You must be signed in to change notification settings - Fork 441
fix: support immutable lists in dynamic header #668
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix: support immutable lists in dynamic header #668
Conversation
This prevents UnsupportedOperationException when using immutable lists such as Arrays.asList、List.of or Collections.unmodifiableList ...
|
|
||
| Assertions.assertEquals(1, list.size()); | ||
| Map<Integer, String> data = list.get(0); | ||
| Assertions.assertEquals("字符串0", data.get(0)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is best to use English.
|
|
||
| import java.io.File; | ||
| import java.text.ParseException; | ||
| import java.util.*; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid using import *
- Use English to describe - Avoid use imports *
|
Thanks for the review. I’ve updated the test code as suggested. |
I considered another approach in #665: In
So I decided not to adopt that solution. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concern on the eager to new, any potential performance impact here?
And meanwhile, head.stream().map(ArrayList::new).collect(Collectors.toList()) is not the deep copy.
| if (null == head || head.isEmpty()) { | ||
| return head; | ||
| } | ||
| return head.stream().map(ArrayList::new).collect(Collectors.toList()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not directly new ArrayList as no any map or reduce required?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’ve replaced the previous stream implementation with a simple for loop to create the copy. I also updated the method description: changed "fully mutable deep copy ..." to "fully mutable of head list" which more accurately reflects the actual behavior.
Purpose of the pull request
Fixed: #665
Avoid
UnsupportedOperationExceptionwhen using immutable list (such as:Arrays.asList、List.oforCollections.unmodifiableList...) in dynamic headerWhat's changed?
AbstractParameterBuilder#headto always convertheadinto a mutable deep copy, preventingUnsupportedOperationExceptionwith immutable lists.ImmutableListHeadDataTest).Checklist