Skip to content

Commit 8e4ae1e

Browse files
committed
Fix IllegalArgumentException when creating IndicesOption with empty Option or WildcardState sets.
Closes spring-projects#2075
1 parent 14cc9ea commit 8e4ae1e

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

Diff for: src/main/java/org/springframework/data/elasticsearch/core/RequestFactory.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -1248,7 +1248,11 @@ public org.elasticsearch.action.support.IndicesOptions toElasticsearchIndicesOpt
12481248
.map(it -> org.elasticsearch.action.support.IndicesOptions.WildcardStates.valueOf(it.name().toUpperCase()))
12491249
.collect(Collectors.toSet());
12501250

1251-
return new org.elasticsearch.action.support.IndicesOptions(EnumSet.copyOf(options), EnumSet.copyOf(wildcardStates));
1251+
return new org.elasticsearch.action.support.IndicesOptions(
1252+
options.isEmpty() ? EnumSet.noneOf(org.elasticsearch.action.support.IndicesOptions.Option.class)
1253+
: EnumSet.copyOf(options),
1254+
wildcardStates.isEmpty() ? EnumSet.noneOf(org.elasticsearch.action.support.IndicesOptions.WildcardStates.class)
1255+
: EnumSet.copyOf(wildcardStates));
12521256
}
12531257
// endregion
12541258

Diff for: src/test/java/org/springframework/data/elasticsearch/core/RequestFactoryTests.java

+18-6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.io.IOException;
2323
import java.time.Duration;
2424
import java.util.Arrays;
25+
import java.util.EnumSet;
2526
import java.util.HashSet;
2627

2728
import org.elasticsearch.action.DocWriteRequest;
@@ -628,14 +629,25 @@ void shouldAllowSourceQueryForReindexWithoutRemote() throws IOException, JSONExc
628629
assertEquals(expected, json, false);
629630
}
630631

632+
@Test // #2075
633+
@DisplayName("should not fail on empty Option set during toElasticsearchIndicesOptions")
634+
void shouldNotFailOnEmptyOptionsOnToElasticsearchIndicesOptions() {
635+
assertThat(requestFactory.toElasticsearchIndicesOptions(new IndicesOptions(
636+
EnumSet.noneOf(IndicesOptions.Option.class), EnumSet.of(IndicesOptions.WildcardStates.OPEN)))).isNotNull();
637+
}
638+
639+
@Test // #2075
640+
@DisplayName("should not fail on empty WildcardState set during toElasticsearchIndicesOptions")
641+
void shouldNotFailOnEmptyWildcardStatesOnToElasticsearchIndicesOptions() {
642+
assertThat(requestFactory.toElasticsearchIndicesOptions(IndicesOptions.STRICT_SINGLE_INDEX_NO_EXPAND_FORBID_CLOSED))
643+
.isNotNull();
644+
}
645+
631646
// region entities
632647
static class Person {
633-
@Nullable
634-
@Id String id;
635-
@Nullable
636-
@Field(name = "last-name") String lastName;
637-
@Nullable
638-
@Field(name = "current-location") GeoPoint location;
648+
@Nullable @Id String id;
649+
@Nullable @Field(name = "last-name") String lastName;
650+
@Nullable @Field(name = "current-location") GeoPoint location;
639651

640652
public Person() {}
641653

0 commit comments

Comments
 (0)