mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-03-27 02:18:42 +00:00
This commit fixes potential NPE when there's V2 template with `null` priority. This is done by using `null`-safe comparator.
This commit is contained in:
parent
f6bdd30165
commit
adc6e880cf
@ -664,7 +664,8 @@ public class MetadataIndexTemplateService {
|
||||
}
|
||||
|
||||
final List<IndexTemplateV2> candidates = new ArrayList<>(matchedTemplates.keySet());
|
||||
CollectionUtil.timSort(candidates, Comparator.comparingLong(IndexTemplateV2::priority).reversed());
|
||||
CollectionUtil.timSort(candidates, Comparator.comparing(IndexTemplateV2::priority,
|
||||
Comparator.nullsLast(Comparator.reverseOrder())));
|
||||
|
||||
assert candidates.size() > 0 : "we should have returned early with no candidates";
|
||||
IndexTemplateV2 winner = candidates.get(0);
|
||||
|
@ -478,7 +478,7 @@ public class MetadataIndexTemplateServiceTests extends ESSingleNodeTestCase {
|
||||
|
||||
ComponentTemplate ct = ComponentTemplateTests.randomInstance();
|
||||
state = service.addComponentTemplate(state, true, "ct", ct);
|
||||
IndexTemplateV2 it = new IndexTemplateV2(Collections.singletonList("i*"), null, Collections.singletonList("ct"), 0L, 1L, null);
|
||||
IndexTemplateV2 it = new IndexTemplateV2(Collections.singletonList("i*"), null, Collections.singletonList("ct"), null, 1L, null);
|
||||
state = service.addIndexTemplateV2(state, true, "my-template", it);
|
||||
IndexTemplateV2 it2 = new IndexTemplateV2(Collections.singletonList("in*"), null, Collections.singletonList("ct"), 10L, 2L, null);
|
||||
state = service.addIndexTemplateV2(state, true, "my-template2", it2);
|
||||
|
Loading…
x
Reference in New Issue
Block a user