|
17 | 17 | import java.io.IOException;
|
18 | 18 | import java.util.ArrayList;
|
19 | 19 | import java.util.Arrays;
|
| 20 | +import java.util.Collection; |
20 | 21 | import java.util.HashMap;
|
21 | 22 | import java.util.List;
|
22 | 23 | import java.util.Locale;
|
@@ -351,15 +352,9 @@ && matchPatternsAreDefined(match, pathMatch, unmatchMappingType))
|
351 | 352 | .toArray(XContentFieldType[]::new);
|
352 | 353 |
|
353 | 354 | final MatchType matchType = MatchType.fromString(matchPattern);
|
354 |
| - List<String> allPatterns = Stream.of(match.stream(), unmatch.stream(), pathMatch.stream(), pathUnmatch.stream()) |
355 |
| - .flatMap(s -> s) |
356 |
| - .toList(); |
357 |
| - for (String pattern : allPatterns) { |
358 |
| - // no need to check return value - the method impls either have side effects (set header warnings) |
359 |
| - // or throw an exception that should be sent back to the user |
360 |
| - matchType.validate(pattern, name); |
361 |
| - } |
362 |
| - |
| 355 | + // no need to check return value - the method impls either have side effects (set header warnings) |
| 356 | + // or throw an exception that should be sent back to the user |
| 357 | + Stream.of(match, unmatch, pathMatch, pathUnmatch).flatMap(Collection::stream).forEach(pattern -> matchType.validate(pattern, name)); |
363 | 358 | return new DynamicTemplate(
|
364 | 359 | name,
|
365 | 360 | pathMatch,
|
@@ -427,13 +422,13 @@ private DynamicTemplate(
|
427 | 422 | boolean runtimeMapping
|
428 | 423 | ) {
|
429 | 424 | this.name = name;
|
430 |
| - this.pathMatch = pathMatch; |
431 |
| - this.pathUnmatch = pathUnmatch; |
432 |
| - this.match = match; |
433 |
| - this.unmatch = unmatch; |
| 425 | + this.pathMatch = List.copyOf(pathMatch); |
| 426 | + this.pathUnmatch = List.copyOf(pathUnmatch); |
| 427 | + this.match = List.copyOf(match); |
| 428 | + this.unmatch = List.copyOf(unmatch); |
434 | 429 | this.matchType = matchType;
|
435 |
| - this.matchMappingType = matchMappingType; |
436 |
| - this.unmatchMappingType = unmatchMappingType; |
| 430 | + this.matchMappingType = List.copyOf(matchMappingType); |
| 431 | + this.unmatchMappingType = List.copyOf(unmatchMappingType); |
437 | 432 | this.xContentFieldTypes = xContentFieldTypes;
|
438 | 433 | this.mapping = mapping;
|
439 | 434 | this.runtimeMapping = runtimeMapping;
|
|
0 commit comments