Skip to content

Commit e7136b8

Browse files
gaobinlongshiv0408
authored andcommitted
Fix null_pointer_exception when creating or updating ingest pipeline (opensearch-project#9259)
* Fix null_pointer_exception when creating or update ingest pipeline Signed-off-by: Gao Binlong <[email protected]> * Modify changelog Signed-off-by: Gao Binlong <[email protected]> * Add nullable tag Signed-off-by: Gao Binlong <[email protected]> * Add more test Signed-off-by: Gao Binlong <[email protected]> * Modify error message Signed-off-by: Gao Binlong <[email protected]> --------- Signed-off-by: Gao Binlong <[email protected]> Signed-off-by: Shivansh Arora <[email protected]>
1 parent 86ae757 commit e7136b8

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
184184

185185
### Fixed
186186
- Fix flaky ResourceAwareTasksTests.testBasicTaskResourceTracking test ([#8993](https://github.com/opensearch-project/OpenSearch/pull/8993))
187+
- Fix null_pointer_exception when creating or updating ingest pipeline ([#9259](https://github.com/opensearch-project/OpenSearch/pull/9259))
187188
- Fix memory leak when using Zstd Dictionary ([#9403](https://github.com/opensearch-project/OpenSearch/pull/9403))
188189
- Fix range reads in respository-s3 ([9512](https://github.com/opensearch-project/OpenSearch/issues/9512))
189190
- Handle null partSize in OnDemandBlockSnapshotIndexInput ([#9291](https://github.com/opensearch-project/OpenSearch/issues/9291))

server/src/main/java/org/opensearch/ingest/ConfigurationUtils.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.opensearch.ExceptionsHelper;
3636
import org.opensearch.OpenSearchException;
3737
import org.opensearch.OpenSearchParseException;
38+
import org.opensearch.common.Nullable;
3839
import org.opensearch.common.xcontent.LoggingDeprecationHandler;
3940
import org.opensearch.common.xcontent.json.JsonXContent;
4041
import org.opensearch.core.common.bytes.BytesReference;
@@ -510,9 +511,11 @@ public static Processor readProcessor(
510511
Map<String, Processor.Factory> processorFactories,
511512
ScriptService scriptService,
512513
String type,
513-
Object config
514+
@Nullable Object config
514515
) throws Exception {
515-
if (config instanceof Map) {
516+
if (config == null) {
517+
throw newConfigurationException(type, null, null, "the config of processor [" + type + "] cannot be null");
518+
} else if (config instanceof Map) {
516519
return readProcessor(processorFactories, scriptService, type, (Map<String, Object>) config);
517520
} else if (config instanceof String && "script".equals(type)) {
518521
Map<String, Object> normalizedScript = new HashMap<>(1);
@@ -527,8 +530,11 @@ public static Processor readProcessor(
527530
Map<String, Processor.Factory> processorFactories,
528531
ScriptService scriptService,
529532
String type,
530-
Map<String, Object> config
533+
@Nullable Map<String, Object> config
531534
) throws Exception {
535+
if (config == null) {
536+
throw newConfigurationException(type, null, null, "expect the config of processor [" + type + "] to be map, but is null");
537+
}
532538
String tag = ConfigurationUtils.readOptionalStringProperty(null, null, config, TAG_KEY);
533539
String description = ConfigurationUtils.readOptionalStringProperty(null, tag, config, DESCRIPTION_KEY);
534540
boolean ignoreFailure = ConfigurationUtils.readBooleanProperty(null, null, config, IGNORE_FAILURE_KEY, false);

server/src/test/java/org/opensearch/ingest/ConfigurationUtilsTests.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,16 @@ public void testReadProcessors() throws Exception {
179179
assertThat(e2.getMetadata("opensearch.processor_tag"), equalTo(Collections.singletonList("my_second_unknown")));
180180
assertThat(e2.getMetadata("opensearch.processor_type"), equalTo(Collections.singletonList("second_unknown_processor")));
181181
assertThat(e2.getMetadata("opensearch.property_name"), is(nullValue()));
182+
183+
// test null config
184+
List<Map<String, Object>> config3 = new ArrayList<>();
185+
config3.add(Collections.singletonMap("null_processor", null));
186+
187+
OpenSearchParseException ex = expectThrows(
188+
OpenSearchParseException.class,
189+
() -> ConfigurationUtils.readProcessorConfigs(config3, scriptService, registry)
190+
);
191+
assertEquals(ex.getMessage(), "the config of processor [null_processor] cannot be null");
182192
}
183193

184194
public void testReadProcessorNullDescription() throws Exception {
@@ -235,6 +245,12 @@ public void testReadProcessorFromObjectOrMap() throws Exception {
235245
() -> ConfigurationUtils.readProcessor(registry, scriptService, "unknown_processor", invalidConfig)
236246
);
237247
assertThat(ex.getMessage(), equalTo("property isn't a map, but of type [" + invalidConfig.getClass().getName() + "]"));
248+
249+
ex = expectThrows(
250+
OpenSearchParseException.class,
251+
() -> ConfigurationUtils.readProcessor(registry, scriptService, "null_processor", null)
252+
);
253+
assertEquals(ex.getMessage(), "expect the config of processor [null_processor] to be map, but is null");
238254
}
239255

240256
public void testNoScriptCompilation() {

0 commit comments

Comments
 (0)