From 26197f3f34cb939c10d9f7a6f01d26246a388081 Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Mon, 4 Sep 2023 12:02:02 -0400 Subject: [PATCH] Fix null_pointer_exception when creating or updating ingest pipeline (#9259) (#9733) * Fix null_pointer_exception when creating or update ingest pipeline * Modify changelog * Add nullable tag * Add more test * Modify error message --------- (cherry picked from commit 4294d444a91c2bde99a20323ba4000bcf6199ba8) Signed-off-by: Gao Binlong Signed-off-by: github-actions[bot] Co-authored-by: github-actions[bot] --- CHANGELOG.md | 1 + .../opensearch/ingest/ConfigurationUtils.java | 12 +++++++++--- .../ingest/ConfigurationUtilsTests.java | 16 ++++++++++++++++ 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a531b58983b46..b1aa45f93ef85 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -114,6 +114,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ### Fixed - Fix flaky ResourceAwareTasksTests.testBasicTaskResourceTracking test ([#8993](https://github.com/opensearch-project/OpenSearch/pull/8993)) +- Fix null_pointer_exception when creating or updating ingest pipeline ([#9259](https://github.com/opensearch-project/OpenSearch/pull/9259)) - Fix memory leak when using Zstd Dictionary ([#9403](https://github.com/opensearch-project/OpenSearch/pull/9403)) - Fix condition to remove index create block ([#9437](https://github.com/opensearch-project/OpenSearch/pull/9437)) - Add support to clear archived index setting ([#9019](https://github.com/opensearch-project/OpenSearch/pull/9019)) diff --git a/server/src/main/java/org/opensearch/ingest/ConfigurationUtils.java b/server/src/main/java/org/opensearch/ingest/ConfigurationUtils.java index 01dafc52d4551..f97388a8262ff 100644 --- a/server/src/main/java/org/opensearch/ingest/ConfigurationUtils.java +++ b/server/src/main/java/org/opensearch/ingest/ConfigurationUtils.java @@ -35,6 +35,7 @@ import org.opensearch.ExceptionsHelper; import org.opensearch.OpenSearchException; import org.opensearch.OpenSearchParseException; +import org.opensearch.common.Nullable; import org.opensearch.common.xcontent.LoggingDeprecationHandler; import org.opensearch.common.xcontent.json.JsonXContent; import org.opensearch.core.common.bytes.BytesReference; @@ -510,9 +511,11 @@ public static Processor readProcessor( Map processorFactories, ScriptService scriptService, String type, - Object config + @Nullable Object config ) throws Exception { - if (config instanceof Map) { + if (config == null) { + throw newConfigurationException(type, null, null, "the config of processor [" + type + "] cannot be null"); + } else if (config instanceof Map) { return readProcessor(processorFactories, scriptService, type, (Map) config); } else if (config instanceof String && "script".equals(type)) { Map normalizedScript = new HashMap<>(1); @@ -527,8 +530,11 @@ public static Processor readProcessor( Map processorFactories, ScriptService scriptService, String type, - Map config + @Nullable Map config ) throws Exception { + if (config == null) { + throw newConfigurationException(type, null, null, "expect the config of processor [" + type + "] to be map, but is null"); + } String tag = ConfigurationUtils.readOptionalStringProperty(null, null, config, TAG_KEY); String description = ConfigurationUtils.readOptionalStringProperty(null, tag, config, DESCRIPTION_KEY); boolean ignoreFailure = ConfigurationUtils.readBooleanProperty(null, null, config, IGNORE_FAILURE_KEY, false); diff --git a/server/src/test/java/org/opensearch/ingest/ConfigurationUtilsTests.java b/server/src/test/java/org/opensearch/ingest/ConfigurationUtilsTests.java index cf67c8af139fb..e18e5887c949e 100644 --- a/server/src/test/java/org/opensearch/ingest/ConfigurationUtilsTests.java +++ b/server/src/test/java/org/opensearch/ingest/ConfigurationUtilsTests.java @@ -179,6 +179,16 @@ public void testReadProcessors() throws Exception { assertThat(e2.getMetadata("opensearch.processor_tag"), equalTo(Collections.singletonList("my_second_unknown"))); assertThat(e2.getMetadata("opensearch.processor_type"), equalTo(Collections.singletonList("second_unknown_processor"))); assertThat(e2.getMetadata("opensearch.property_name"), is(nullValue())); + + // test null config + List> config3 = new ArrayList<>(); + config3.add(Collections.singletonMap("null_processor", null)); + + OpenSearchParseException ex = expectThrows( + OpenSearchParseException.class, + () -> ConfigurationUtils.readProcessorConfigs(config3, scriptService, registry) + ); + assertEquals(ex.getMessage(), "the config of processor [null_processor] cannot be null"); } public void testReadProcessorNullDescription() throws Exception { @@ -235,6 +245,12 @@ public void testReadProcessorFromObjectOrMap() throws Exception { () -> ConfigurationUtils.readProcessor(registry, scriptService, "unknown_processor", invalidConfig) ); assertThat(ex.getMessage(), equalTo("property isn't a map, but of type [" + invalidConfig.getClass().getName() + "]")); + + ex = expectThrows( + OpenSearchParseException.class, + () -> ConfigurationUtils.readProcessor(registry, scriptService, "null_processor", null) + ); + assertEquals(ex.getMessage(), "expect the config of processor [null_processor] to be map, but is null"); } public void testNoScriptCompilation() {