Fix failure in InnerHitBuilderTests around 'fields' option. (#62344)
The case InnerHitBuilderTests#testEqualsAndHashcode creates a copy of the object by serializing + deserializing it, then applies a modification. If the 'fields' list is empty, then deserializing it results in Collections.emptyList. Because this is immutable, then modifying it can throw an UnsupportedOperationException. This PR takes the same approach as for docvalue_fields, where we create a new list instead of trying to add to an empty one.
This commit is contained in:
parent
9332a9c74b
commit
f56ce4f39b
|
@ -424,7 +424,7 @@ public final class InnerHitBuilder implements Writeable, ToXContentObject {
|
|||
* @param format an optional format string used when formatting values, for example a date format.
|
||||
*/
|
||||
public InnerHitBuilder addFetchField(String name, @Nullable String format) {
|
||||
if (fetchFields == null) {
|
||||
if (fetchFields == null || fetchFields.isEmpty()) {
|
||||
fetchFields = new ArrayList<>();
|
||||
}
|
||||
fetchFields.add(new FieldAndFormat(name, format));
|
||||
|
|
Loading…
Reference in New Issue