浏览代码

Fix failure in InnerHitBuilderTests around 'fields' option. (#62341)

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.
Julie Tibshirani 5 年之前
父节点
当前提交
c1d9037647
共有 1 个文件被更改,包括 1 次插入1 次删除
  1. 1 1
      server/src/main/java/org/elasticsearch/index/query/InnerHitBuilder.java

+ 1 - 1
server/src/main/java/org/elasticsearch/index/query/InnerHitBuilder.java

@@ -395,7 +395,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));