Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
Signed-off-by: zane-neo <zaniu@amazon.com>
  • Loading branch information
zane-neo committed Jun 4, 2024
1 parent bb82974 commit 85cd1ec
Showing 1 changed file with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;

/**
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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));
}
}
});
Expand All @@ -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,
Expand All @@ -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));
}
}
}
Expand All @@ -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));
}
}
}

0 comments on commit 85cd1ec

Please sign in to comment.