mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
8241988: DatagramSocket incorrectly caches the first set of socket options
Reviewed-by: msheppar, dfuchs, alanb
This commit is contained in:
parent
a76f0f78ad
commit
61940fe4ce
3 changed files with 242 additions and 27 deletions
|
@ -1483,8 +1483,8 @@ public class DatagramSocket implements java.io.Closeable {
|
|||
return getImpl().getOption(name);
|
||||
}
|
||||
|
||||
private static Set<SocketOption<?>> options;
|
||||
private static boolean optionsSet = false;
|
||||
private volatile Set<SocketOption<?>> options;
|
||||
private final Object optionsLock = new Object();
|
||||
|
||||
/**
|
||||
* Returns a set of the socket options supported by this socket.
|
||||
|
@ -1498,18 +1498,22 @@ public class DatagramSocket implements java.io.Closeable {
|
|||
* @since 9
|
||||
*/
|
||||
public Set<SocketOption<?>> supportedOptions() {
|
||||
synchronized(DatagramSocket.class) {
|
||||
if (optionsSet) {
|
||||
Set<SocketOption<?>> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -808,24 +808,4 @@ public class MulticastSocket extends DatagramSocket {
|
|||
} // synch p
|
||||
} //synch ttl
|
||||
} //method
|
||||
|
||||
private static Set<SocketOption<?>> options;
|
||||
private static boolean optionsSet = false;
|
||||
|
||||
@Override
|
||||
public Set<SocketOption<?>> supportedOptions() {
|
||||
synchronized (MulticastSocket.class) {
|
||||
if (optionsSet) {
|
||||
return options;
|
||||
}
|
||||
try {
|
||||
DatagramSocketImpl impl = getImpl();
|
||||
options = Collections.unmodifiableSet(impl.supportedOptions());
|
||||
} catch (SocketException ex) {
|
||||
options = Collections.emptySet();
|
||||
}
|
||||
optionsSet = true;
|
||||
return options;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue