Replace unmodifiable collection creation with collection factory methods

This commit is contained in:
Mahmoud Ben Hassine
2023-06-12 15:42:02 +02:00
parent cb1b68d165
commit a2be6ba0c3
3 changed files with 17 additions and 19 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2022 the original author or authors.
* Copyright 2006-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -239,7 +239,7 @@ public class JobExecution extends Entity {
* @return the step executions that were registered.
*/
public Collection<StepExecution> getStepExecutions() {
return Collections.unmodifiableList(new ArrayList<>(stepExecutions));
return List.copyOf(stepExecutions);
}
/**

View File

@@ -284,22 +284,20 @@ public class Jackson2ExecutionContextStringSerializer implements ExecutionContex
*/
static class TrustedTypeIdResolver implements TypeIdResolver {
private static final Set<String> TRUSTED_CLASS_NAMES = Collections
.unmodifiableSet(new HashSet<>(Arrays.asList("javax.xml.namespace.QName", "java.util.UUID",
"java.util.ArrayList", "java.util.Arrays$ArrayList", "java.util.LinkedList",
"java.util.Collections$EmptyList", "java.util.Collections$EmptyMap",
"java.util.Collections$EmptySet", "java.util.Collections$UnmodifiableRandomAccessList",
"java.util.Collections$UnmodifiableList", "java.util.Collections$UnmodifiableMap",
"java.util.Collections$UnmodifiableSet", "java.util.Collections$SingletonList",
"java.util.Collections$SingletonMap", "java.util.Collections$SingletonSet", "java.util.Date",
"java.time.Instant", "java.time.Duration", "java.time.LocalDate", "java.time.LocalTime",
"java.time.LocalDateTime", "java.sql.Timestamp", "java.net.URL", "java.util.TreeMap",
"java.util.HashMap", "java.util.LinkedHashMap", "java.util.TreeSet", "java.util.HashSet",
"java.util.LinkedHashSet", "java.lang.Boolean", "java.lang.Byte", "java.lang.Short",
"java.lang.Integer", "java.lang.Long", "java.lang.Double", "java.lang.Float",
"java.math.BigDecimal", "java.math.BigInteger", "java.lang.String", "java.lang.Character",
"java.lang.CharSequence", "java.util.Properties", "[Ljava.util.Properties;",
"org.springframework.batch.core.JobParameter", "org.springframework.batch.core.JobParameters")));
private static final Set<String> TRUSTED_CLASS_NAMES = Set.of("javax.xml.namespace.QName", "java.util.UUID",
"java.util.ArrayList", "java.util.Arrays$ArrayList", "java.util.LinkedList",
"java.util.Collections$EmptyList", "java.util.Collections$EmptyMap", "java.util.Collections$EmptySet",
"java.util.Collections$UnmodifiableRandomAccessList", "java.util.Collections$UnmodifiableList",
"java.util.Collections$UnmodifiableMap", "java.util.Collections$UnmodifiableSet",
"java.util.Collections$SingletonList", "java.util.Collections$SingletonMap",
"java.util.Collections$SingletonSet", "java.util.Date", "java.time.Instant", "java.time.Duration",
"java.time.LocalDate", "java.time.LocalTime", "java.time.LocalDateTime", "java.sql.Timestamp",
"java.net.URL", "java.util.TreeMap", "java.util.HashMap", "java.util.LinkedHashMap",
"java.util.TreeSet", "java.util.HashSet", "java.util.LinkedHashSet", "java.lang.Boolean",
"java.lang.Byte", "java.lang.Short", "java.lang.Integer", "java.lang.Long", "java.lang.Double",
"java.lang.Float", "java.math.BigDecimal", "java.math.BigInteger", "java.lang.String",
"java.lang.Character", "java.lang.CharSequence", "java.util.Properties", "[Ljava.util.Properties;",
"org.springframework.batch.core.JobParameter", "org.springframework.batch.core.JobParameters");
private final Set<String> trustedClassNames = new LinkedHashSet<>(TRUSTED_CLASS_NAMES);

View File

@@ -103,7 +103,7 @@ public class Chunk<W> implements Iterable<W>, Serializable {
* @return a copy of the items to be processed as an unmodifiable list
*/
public List<W> getItems() {
return Collections.unmodifiableList(new ArrayList<>(items));
return List.copyOf(items);
}
/**