--- old/src/java.base/share/classes/java/net/DatagramSocket.java 2020-04-01 16:01:18.000000000 +0100 +++ new/src/java.base/share/classes/java/net/DatagramSocket.java 2020-04-01 16:01:18.000000000 +0100 @@ -1483,8 +1483,8 @@ return getImpl().getOption(name); } - private static Set> options; - private static boolean optionsSet = false; + /*package*/ volatile Set> options; + private final Object optionsLock = new Object(); /** * Returns a set of the socket options supported by this socket. @@ -1498,18 +1498,22 @@ * @since 9 */ public Set> supportedOptions() { - synchronized(DatagramSocket.class) { - if (optionsSet) { + Set> options = this.options; + if (options != null) + return options; + + synchronized (optionsLock) { + options = this.options; + if (options != null) return options; - } + try { DatagramSocketImpl impl = getImpl(); options = Collections.unmodifiableSet(impl.supportedOptions()); } catch (IOException e) { options = Collections.emptySet(); } - optionsSet = true; - return options; + return this.options = options; } } }