From 85cd1ec8978ed70b7bb043b2c14f04676ba11750 Mon Sep 17 00:00:00 2001 From: zane-neo Date: Tue, 4 Jun 2024 09:13:19 +0800 Subject: [PATCH] address comments Signed-off-by: zane-neo --- .../util/ProcessorDocumentUtils.java | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/opensearch/neuralsearch/util/ProcessorDocumentUtils.java b/src/main/java/org/opensearch/neuralsearch/util/ProcessorDocumentUtils.java index fbaad628e..1e691b3b6 100644 --- a/src/main/java/org/opensearch/neuralsearch/util/ProcessorDocumentUtils.java +++ b/src/main/java/org/opensearch/neuralsearch/util/ProcessorDocumentUtils.java @@ -15,6 +15,7 @@ import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Objects; import java.util.Optional; /** @@ -58,7 +59,9 @@ private static void validateMapTypeValue( final Environment environment, final boolean allowEmpty ) { - if (sourceValue == null) return; // allow map type value to be null. + if (Objects.isNull(sourceValue)) { // allow map type value to be null. + return; + } validateDepth(sourceKey, depth, indexName, clusterService, environment); if (!(fieldMap instanceof Map)) { // source value is map type means configuration has to be map type throw new IllegalArgumentException( @@ -98,9 +101,9 @@ private static void validateMapTypeValue( allowEmpty ); } else if (!(nextSourceValue instanceof String)) { - throw new IllegalArgumentException("map type field [" + key + "] is neither string nor nested type, cannot process it"); + throw new IllegalArgumentException(String.format(Locale.getDefault(), "map type field [%s] is neither string nor nested type, cannot process it", key)); } else if (!allowEmpty && StringUtils.isBlank((String) nextSourceValue)) { - throw new IllegalArgumentException("map type field [" + key + "] has empty string value, cannot process it"); + throw new IllegalArgumentException(String.format(Locale.getDefault(), "map type field [%s] has empty string value, cannot process it", key)); } } }); @@ -118,13 +121,15 @@ private static void validateListTypeValue( final boolean allowEmpty ) { validateDepth(sourceKey, depth, indexName, clusterService, environment); - if (CollectionUtils.isEmpty(sourceValue)) return; + if (CollectionUtils.isEmpty(sourceValue)) { + return; + } for (Object element : sourceValue) { - if (element == null) { - throw new IllegalArgumentException("list type field [" + sourceKey + "] has null, cannot process it"); + if (Objects.isNull(element)) { + throw new IllegalArgumentException(String.format(Locale.getDefault(), "list type field [%s] has null, cannot process it", sourceKey)); } if (element instanceof List) { // nested list case. - throw new IllegalArgumentException("list type field [" + sourceKey + "] is nested list type, cannot process it"); + throw new IllegalArgumentException(String.format(Locale.getDefault(), "list type field [%s] is nested list type, cannot process it", sourceKey)); } else if (element instanceof Map) { validateMapTypeValue( sourceKey, @@ -137,9 +142,9 @@ private static void validateListTypeValue( allowEmpty ); } else if (!(element instanceof String)) { - throw new IllegalArgumentException("list type field [" + sourceKey + "] has non string value, cannot process it"); + throw new IllegalArgumentException(String.format(Locale.getDefault(), "list type field [%s] has non string value, cannot process it", sourceKey)); } else if (!allowEmpty && StringUtils.isBlank(element.toString())) { - throw new IllegalArgumentException("list type field [" + sourceKey + "] has empty string, cannot process it"); + throw new IllegalArgumentException(String.format(Locale.getDefault(), "list type field [%s] has empty string, cannot process it", sourceKey)); } } } @@ -156,7 +161,7 @@ private static void validateDepth( .orElse(environment.settings()); long maxDepth = MapperService.INDEX_MAPPING_DEPTH_LIMIT_SETTING.get(settings); if (depth > maxDepth) { - throw new IllegalArgumentException("map type field [" + sourceKey + "] reaches max depth limit, cannot process it"); + throw new IllegalArgumentException(String.format(Locale.getDefault(), "map type field [%s] reaches max depth limit, cannot process it", sourceKey)); } } }