--- a/src/java.base/share/classes/java/net/ServerSocket.java Thu Nov 08 10:36:06 2018 -0500
+++ b/src/java.base/share/classes/java/net/ServerSocket.java Thu Nov 08 16:16:57 2018 +0000
@@ -993,8 +993,8 @@
return getImpl().getOption(name);
}
- private static Set<SocketOption<?>> options;
- private static boolean optionsSet = false;
+ // cache of unmodifiable impl options. Possibly set racy, in impl we trust
+ private volatile Set<SocketOption<?>> options;
/**
* Returns a set of the socket options supported by this server socket.
@@ -1008,19 +1008,17 @@
* @since 9
*/
public Set<SocketOption<?>> supportedOptions() {
- synchronized (ServerSocket.class) {
- if (optionsSet) {
- return options;
- }
- try {
- SocketImpl impl = getImpl();
- options = Collections.unmodifiableSet(impl.supportedOptions());
- } catch (IOException e) {
- options = Collections.emptySet();
- }
- optionsSet = true;
- return options;
+ Set<SocketOption<?>> so = options;
+ if (so != null)
+ return so;
+
+ try {
+ SocketImpl impl = getImpl();
+ options = Collections.unmodifiableSet(impl.supportedOptions());
+ } catch (IOException e) {
+ options = Collections.emptySet();
}
+ return options;
}
static {