mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-06-28 14:52:20 +00:00
Fix IllegalArgumentException when creating custom IndicesOption with empty Option or WildcardState set.
Original Pull Request #2076 Closes #2075
This commit is contained in:
parent
14cc9ea495
commit
f37eec641b
@ -118,6 +118,7 @@ import org.springframework.util.StringUtils;
|
||||
* @author Farid Faoudi
|
||||
* @author Peer Mueller
|
||||
* @author Sijia Liu
|
||||
* @author Peter Nowak
|
||||
* @since 4.0
|
||||
*/
|
||||
class RequestFactory {
|
||||
@ -1248,7 +1249,11 @@ class RequestFactory {
|
||||
.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
|
||||
|
||||
|
@ -22,6 +22,7 @@ import static org.skyscreamer.jsonassert.JSONAssert.*;
|
||||
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;
|
||||
@ -70,6 +71,7 @@ import org.springframework.lang.Nullable;
|
||||
* @author Peer Mueller
|
||||
* @author vdisk
|
||||
* @author Sijia Liu
|
||||
* @author Peter Nowak
|
||||
*/
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@ -628,6 +630,20 @@ class RequestFactoryTests {
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user