diff --git a/api/src/org/labkey/api/data/NameGenerator.java b/api/src/org/labkey/api/data/NameGenerator.java index 517d7f3574e..7e45d053587 100644 --- a/api/src/org/labkey/api/data/NameGenerator.java +++ b/api/src/org/labkey/api/data/NameGenerator.java @@ -729,7 +729,7 @@ protected int write() .filter(s -> !s.isEmpty()); } - public static Stream parentNames(Object value, String parentColName, TSVWriter tsvWriter, @Nullable BatchValidationException errors) + public static @Nullable Stream parentNames(Object value, String parentColName, TSVWriter tsvWriter, @Nullable BatchValidationException errors) { if (value == null) return Stream.empty(); @@ -783,6 +783,21 @@ else if (value instanceof JSONArray jsonArray) throw new IllegalStateException("For parent values in naming pattern, expected string or collection for '" + parentColName + "': " + value); } + if (values != null) + { + List valueList = values.toList(); + Set valueSet = new HashSet<>(); + List duplicates = valueList.stream().filter(s -> !valueSet.add(s)).toList(); + if (!duplicates.isEmpty()) + { + if (errors != null) + errors.addRowError(new ValidationException("Duplicate parent names found: " + StringUtils.join(duplicates, ", "), parentColName)); + else + throw new IllegalStateException("Duplicate parent names found: " + StringUtils.join(duplicates, ", ")); + } + return valueList.stream(); + } + return values; }