Skip to content

Commit

Permalink
Fix IllegalArgumentException when creating custom IndicesOption with …
Browse files Browse the repository at this point in the history
…empty Option or WildcardState set.

Closes spring-projects#2075
  • Loading branch information
pnowak85 committed Feb 1, 2022
1 parent 14cc9ea commit 89162de
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
* @author Farid Faoudi
* @author Peer Mueller
* @author Sijia Liu
* @author Peter Nowak
* @since 4.0
*/
class RequestFactory {
Expand Down Expand Up @@ -1248,7 +1249,11 @@ public org.elasticsearch.action.support.IndicesOptions toElasticsearchIndicesOpt
.map(it -> org.elasticsearch.action.support.IndicesOptions.WildcardStates.valueOf(it.name().toUpperCase()))
.collect(Collectors.toSet());

return new org.elasticsearch.action.support.IndicesOptions(EnumSet.copyOf(options), EnumSet.copyOf(wildcardStates));
return new org.elasticsearch.action.support.IndicesOptions(
options.isEmpty() ? EnumSet.noneOf(org.elasticsearch.action.support.IndicesOptions.Option.class)
: EnumSet.copyOf(options),
wildcardStates.isEmpty() ? EnumSet.noneOf(org.elasticsearch.action.support.IndicesOptions.WildcardStates.class)
: EnumSet.copyOf(wildcardStates));
}
// endregion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.io.IOException;
import java.time.Duration;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.HashSet;

import org.elasticsearch.action.DocWriteRequest;
Expand Down Expand Up @@ -70,6 +71,7 @@
* @author Peer Mueller
* @author vdisk
* @author Sijia Liu
* @author Peter Nowak
*/
@SuppressWarnings("ConstantConditions")
@ExtendWith(MockitoExtension.class)
Expand Down Expand Up @@ -628,6 +630,20 @@ void shouldAllowSourceQueryForReindexWithoutRemote() throws IOException, JSONExc
assertEquals(expected, json, false);
}

@Test // #2075
@DisplayName("should not fail on empty Option set during toElasticsearchIndicesOptions")
void shouldNotFailOnEmptyOptionsOnToElasticsearchIndicesOptions() {
assertThat(requestFactory.toElasticsearchIndicesOptions(new IndicesOptions(
EnumSet.noneOf(IndicesOptions.Option.class), EnumSet.of(IndicesOptions.WildcardStates.OPEN)))).isNotNull();
}

@Test // #2075
@DisplayName("should not fail on empty WildcardState set during toElasticsearchIndicesOptions")
void shouldNotFailOnEmptyWildcardStatesOnToElasticsearchIndicesOptions() {
assertThat(requestFactory.toElasticsearchIndicesOptions(IndicesOptions.STRICT_SINGLE_INDEX_NO_EXPAND_FORBID_CLOSED))
.isNotNull();
}

// region entities
static class Person {
@Nullable
Expand Down

0 comments on commit 89162de

Please sign in to comment.