mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-26 22:34:27 +02:00
8281298: Revise the creation of unmodifiable list
Reviewed-by: redestad
This commit is contained in:
parent
5dfff7406e
commit
f2302822c0
1 changed files with 49 additions and 56 deletions
|
@ -26,12 +26,7 @@
|
|||
package javax.net.ssl;
|
||||
|
||||
import java.security.AlgorithmConstraints;
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
import java.util.HashMap;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Encapsulates parameters for an SSL/TLS/DTLS connection. The parameters
|
||||
|
@ -81,8 +76,8 @@ public class SSLParameters {
|
|||
private boolean needClientAuth;
|
||||
private String identificationAlgorithm;
|
||||
private AlgorithmConstraints algorithmConstraints;
|
||||
private Map<Integer, SNIServerName> sniNames = null;
|
||||
private Map<Integer, SNIMatcher> sniMatchers = null;
|
||||
private List<SNIServerName> sniNames = null; // immutable list
|
||||
private Collection<SNIMatcher> sniMatchers = null; // immutable collection
|
||||
private boolean preferLocalCipherSuites;
|
||||
private boolean enableRetransmissions = true;
|
||||
private int maximumPacketSize = 0;
|
||||
|
@ -331,22 +326,29 @@ public class SSLParameters {
|
|||
* @since 1.8
|
||||
*/
|
||||
public final void setServerNames(List<SNIServerName> serverNames) {
|
||||
if (serverNames != null) {
|
||||
if (!serverNames.isEmpty()) {
|
||||
sniNames = new LinkedHashMap<>(serverNames.size());
|
||||
for (SNIServerName serverName : serverNames) {
|
||||
if (sniNames.put(serverName.getType(),
|
||||
serverName) != null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Duplicated server name of type " +
|
||||
serverName.getType());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
sniNames = Collections.<Integer, SNIServerName>emptyMap();
|
||||
}
|
||||
} else {
|
||||
if (this.sniNames == serverNames) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (serverNames == null) {
|
||||
sniNames = null;
|
||||
} else if (serverNames.isEmpty()) {
|
||||
sniNames = Collections.emptyList();
|
||||
} else {
|
||||
List<Integer> sniTypes = new ArrayList<>(serverNames.size());
|
||||
List<SNIServerName> sniValues = new ArrayList<>(serverNames.size());
|
||||
for (SNIServerName serverName : serverNames) {
|
||||
if (sniTypes.contains(serverName.getType())) {
|
||||
throw new IllegalArgumentException(
|
||||
"Duplicated server name of type " +
|
||||
serverName.getType());
|
||||
} else {
|
||||
sniTypes.add(serverName.getType());
|
||||
sniValues.add(serverName);
|
||||
}
|
||||
}
|
||||
|
||||
sniNames = Collections.unmodifiableList(sniValues);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -388,15 +390,7 @@ public class SSLParameters {
|
|||
* @since 1.8
|
||||
*/
|
||||
public final List<SNIServerName> getServerNames() {
|
||||
if (sniNames != null) {
|
||||
if (!sniNames.isEmpty()) {
|
||||
return List.copyOf(sniNames.values());
|
||||
} else {
|
||||
return Collections.<SNIServerName>emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
return sniNames;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -424,22 +418,29 @@ public class SSLParameters {
|
|||
* @since 1.8
|
||||
*/
|
||||
public final void setSNIMatchers(Collection<SNIMatcher> matchers) {
|
||||
if (matchers != null) {
|
||||
if (!matchers.isEmpty()) {
|
||||
sniMatchers = new HashMap<>(matchers.size());
|
||||
for (SNIMatcher matcher : matchers) {
|
||||
if (sniMatchers.put(matcher.getType(),
|
||||
matcher) != null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Duplicated server name of type " +
|
||||
matcher.getType());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
sniMatchers = Collections.<Integer, SNIMatcher>emptyMap();
|
||||
}
|
||||
if (this.sniMatchers == matchers) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (matchers == null) {
|
||||
this.sniMatchers = null;
|
||||
} else if (matchers.isEmpty()) {
|
||||
sniMatchers = Collections.emptyList();
|
||||
} else {
|
||||
sniMatchers = null;
|
||||
List<Integer> matcherTypes = new ArrayList<>(matchers.size());
|
||||
List<SNIMatcher> matcherValues = new ArrayList<>(matchers.size());
|
||||
for (SNIMatcher matcher : matchers) {
|
||||
if (matcherTypes.contains(matcher.getType())) {
|
||||
throw new IllegalArgumentException(
|
||||
"Duplicated server name of type " +
|
||||
matcher.getType());
|
||||
} else {
|
||||
matcherTypes.add(matcher.getType());
|
||||
matcherValues.add(matcher);
|
||||
}
|
||||
}
|
||||
|
||||
this.sniMatchers = Collections.unmodifiableList(matcherValues);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -462,15 +463,7 @@ public class SSLParameters {
|
|||
* @since 1.8
|
||||
*/
|
||||
public final Collection<SNIMatcher> getSNIMatchers() {
|
||||
if (sniMatchers != null) {
|
||||
if (!sniMatchers.isEmpty()) {
|
||||
return List.copyOf(sniMatchers.values());
|
||||
} else {
|
||||
return Collections.<SNIMatcher>emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
return sniMatchers;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue