Skip to content

Commit 5d37833

Browse files
[8.18] Fix NPE in deprecation API (#121263) (#121319)
* Fix NPE in deprecation API (#121263) **Reproduction path** 1. Create an composable index template that does not have a `template` section. 2. Set some settings in `deprecation.skip_deprecated_settings` 3. Run the deprecation API `GET _migration/deprecations?error_trace` 4. **Result:** we receive an error `500` with the following error and stack trace: ``` .... "reason": "Cannot invoke \"org.elasticsearch.cluster.metadata.Template.settings()\" because \"template\" is null", "stack_trace": "java.lang.NullPointerException: Cannot invoke \"org.elasticsearch.cluster.metadata.Template.settings()\" because \"template\" is null org.elasticsearch.xpack.deprecation.DeprecationInfoAction.lambda$removeSkippedSettings$9(DeprecationInfoAction.java:408) .... ``` **Fix** There was a typo when we were performing the null-check, we used `templateName` instead of `template`. In this PR we fix this and we extend the current test to capture this case as well. The bug is not released so it's marked as a non-issue. * Mute org.elasticsearch.backwards.MixedClusterClientYamlTestSuiteIT test {p0=nodes.stats/11_indices_metrics/indices mappings exact count test for indices level} * Revert wrong mute --------- Co-authored-by: elasticsearchmachine <[email protected]>
1 parent 4e59fb5 commit 5d37833

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationInfoAction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ public static DeprecationInfoAction.Response from(
353353
}
354354

355355
/**
356-
*
356+
* Removes the skipped settings from the selected indices and the component and index templates.
357357
* @param state The cluster state to modify
358358
* @param indexNames The names of the indexes whose settings need to be filtered
359359
* @param skipTheseDeprecatedSettings The settings that will be removed from cluster metadata and the index metadata of all the
@@ -405,7 +405,7 @@ private static ClusterState removeSkippedSettings(ClusterState state, String[] i
405405
String templateName = entry.getKey();
406406
ComposableIndexTemplate indexTemplate = entry.getValue();
407407
Template template = indexTemplate.template();
408-
if (templateName == null || template.settings() == null || template.settings().isEmpty()) {
408+
if (template == null || template.settings() == null || template.settings().isEmpty()) {
409409
return Tuple.tuple(templateName, indexTemplate);
410410
}
411411
return Tuple.tuple(

x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/DeprecationInfoActionResponseTests.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,14 @@ public void testRemoveSkippedSettings() {
362362
.put(IndexMetadata.builder("test").settings(inputSettings).numberOfShards(1).numberOfReplicas(0))
363363
.put(dataStreamIndexMetadata, true)
364364
.put(DataStream.builder("ds-test", List.of(dataStreamIndexMetadata.getIndex())).build())
365-
.indexTemplates(Map.of("my-index-template", indexTemplate))
365+
.indexTemplates(
366+
Map.of(
367+
"my-index-template",
368+
indexTemplate,
369+
"empty-template",
370+
ComposableIndexTemplate.builder().indexPatterns(List.of("random")).build()
371+
)
372+
)
366373
.componentTemplates(Map.of("my-component-template", componentTemplate))
367374
.persistentSettings(inputSettings)
368375
.build();
@@ -391,7 +398,11 @@ public void testRemoveSkippedSettings() {
391398
.componentTemplates()
392399
.values()
393400
.forEach(template -> visibleComponentTemplateSettings.set(template.template().settings()));
394-
cs.metadata().templatesV2().values().forEach(template -> visibleIndexTemplateSettings.set(template.template().settings()));
401+
cs.metadata().templatesV2().values().forEach(template -> {
402+
if (template.template() != null && template.template().settings() != null) {
403+
visibleIndexTemplateSettings.set(template.template().settings());
404+
}
405+
});
395406
return Map.of();
396407
}));
397408

0 commit comments

Comments
 (0)