Revise contribution

This commit reverts changes to AbstractCacheManager since iterating
over the caches in a for-loop and a stream is duplicated effort.

This commit reverts changes to DefaultRenderingResponseBuilder,
RouterFunctions, and OriginHandshakeInterceptor since order matters for
those use cases: they were originally based on the semantics of
LinkedHashSet or LinkedHashMap; whereas, Set.copyOf() and Map.copyOf()
do not provide any guarantees regarding ordering.

This commit also applies analogous changes to "sibling" implementations
across Servlet mocks as well as Web MVC and WebFlux.

See gh-29321
This commit is contained in:
Sam Brannen
2022-11-08 13:50:45 +01:00
parent ba136dcf40
commit 95f3337bb5
13 changed files with 31 additions and 43 deletions

View File

@@ -19,9 +19,9 @@ package org.springframework.web.socket.server.support;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -95,8 +95,9 @@ public class OriginHandshakeInterceptor implements HandshakeInterceptor {
* @since 4.1.5
*/
public Collection<String> getAllowedOrigins() {
return (CollectionUtils.isEmpty(this.corsConfiguration.getAllowedOrigins()) ? Collections.emptySet() :
Set.copyOf(this.corsConfiguration.getAllowedOrigins()));
List<String> allowedOrigins = this.corsConfiguration.getAllowedOrigins();
return (CollectionUtils.isEmpty(allowedOrigins) ? Collections.emptySet() :
Collections.unmodifiableSet(new LinkedHashSet<>(allowedOrigins)));
}
/**
@@ -118,8 +119,9 @@ public class OriginHandshakeInterceptor implements HandshakeInterceptor {
* @since 5.3.2
*/
public Collection<String> getAllowedOriginPatterns() {
return (CollectionUtils.isEmpty(this.corsConfiguration.getAllowedOriginPatterns()) ? Collections.emptySet() :
Set.copyOf(this.corsConfiguration.getAllowedOriginPatterns()));
List<String> allowedOriginPatterns = this.corsConfiguration.getAllowedOriginPatterns();
return (CollectionUtils.isEmpty(allowedOriginPatterns) ? Collections.emptySet() :
Collections.unmodifiableSet(new LinkedHashSet<>(allowedOriginPatterns)));
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2022 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.
@@ -49,6 +49,7 @@ public enum TransportType {
private static final Map<String, TransportType> TRANSPORT_TYPES =
Arrays.stream(values()).collect(Collectors.toUnmodifiableMap(type -> type.value, type -> type));
@Nullable
public static TransportType fromValue(String value) {
return TRANSPORT_TYPES.get(value);