Replace Collections.unmodifiableList(new ArrayList(..)) with List.copyOf() (#30166)

This commit is contained in:
SW
2023-04-12 20:07:20 +09:00
committed by GitHub
parent 695601aa06
commit 59c65fa940
4 changed files with 4 additions and 7 deletions

View File

@@ -17,7 +17,6 @@
package org.springframework.messaging.handler.annotation.reactive;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
@@ -93,7 +92,7 @@ public class PayloadMethodArgumentResolver implements HandlerMethodArgumentResol
@Nullable ReactiveAdapterRegistry registry, boolean useDefaultResolution) {
Assert.isTrue(!CollectionUtils.isEmpty(decoders), "At least one Decoder is required");
this.decoders = Collections.unmodifiableList(new ArrayList<>(decoders));
this.decoders = List.copyOf(decoders);
this.validator = validator;
this.adapterRegistry = registry != null ? registry : ReactiveAdapterRegistry.getSharedInstance();
this.useDefaultResolution = useDefaultResolution;

View File

@@ -16,7 +16,6 @@
package org.springframework.messaging.rsocket;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
@@ -73,7 +72,7 @@ public class DefaultMetadataExtractor implements MetadataExtractor, MetadataExtr
* Constructor with list of decoders for de-serializing metadata entries.
*/
public DefaultMetadataExtractor(List<Decoder<?>> decoders) {
this.decoders = Collections.unmodifiableList(new ArrayList<>(decoders));
this.decoders = List.copyOf(decoders);
}

View File

@@ -19,7 +19,6 @@ package org.springframework.http.converter;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@@ -100,7 +99,7 @@ public abstract class AbstractHttpMessageConverter<T> implements HttpMessageConv
*/
public void setSupportedMediaTypes(List<MediaType> supportedMediaTypes) {
Assert.notEmpty(supportedMediaTypes, "MediaType List must not be empty");
this.supportedMediaTypes = Collections.unmodifiableList(new ArrayList<>(supportedMediaTypes));
this.supportedMediaTypes = List.copyOf(supportedMediaTypes);
}
@Override

View File

@@ -949,7 +949,7 @@ final class HierarchicalUriComponents extends UriComponents {
public PathSegmentComponent(List<String> pathSegments) {
Assert.notNull(pathSegments, "List must not be null");
this.pathSegments = Collections.unmodifiableList(new ArrayList<>(pathSegments));
this.pathSegments = List.copyOf(pathSegments);
}
@Override