Skip to content

Commit

Permalink
Fix failure in InnerHitBuilderTests around 'fields' option. (#62344)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jtibshirani authored Sep 14, 2020
1 parent 9332a9c commit f56ce4f
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ public InnerHitBuilder addFetchField(String name) {
* @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));
Expand Down

0 comments on commit f56ce4f

Please sign in to comment.