diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/LifecyclePolicyUtils.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/LifecyclePolicyUtils.java index f5c9cf1b4253b..94b3647100f54 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/LifecyclePolicyUtils.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/LifecyclePolicyUtils.java @@ -56,17 +56,24 @@ public static LifecyclePolicy loadPolicy( } } + /** + * Parses lifecycle policy based on the provided content type without doing any variable substitution. + * It is caller's responsibility to do any variable substitution if required. + */ public static LifecyclePolicy parsePolicy( String rawPolicy, String name, NamedXContentRegistry xContentRegistry, XContentType contentType ) throws IOException { - XContentParser parser = contentType.xContent() - .createParser(XContentParserConfiguration.EMPTY.withRegistry(xContentRegistry), rawPolicy); - LifecyclePolicy policy = LifecyclePolicy.parse(parser, name); - policy.validate(); - return policy; + try ( + XContentParser parser = contentType.xContent() + .createParser(XContentParserConfiguration.EMPTY.withRegistry(xContentRegistry), rawPolicy) + ) { + LifecyclePolicy policy = LifecyclePolicy.parse(parser, name); + policy.validate(); + return policy; + } } private static String replaceVariables(String template, Map variables) {