mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8238231: Custom DatagramSocketImpl's create method not called when with protected constructor
Allow the socket to be lazily created if not created by the constructor. Reviewed-by: alanb
This commit is contained in:
parent
e104b4cee1
commit
b069da31e0
3 changed files with 148 additions and 19 deletions
|
@ -118,7 +118,8 @@ public class DatagramSocket implements java.io.Closeable {
|
|||
*/
|
||||
private boolean bound = false;
|
||||
private boolean closed = false;
|
||||
private Object closeLock = new Object();
|
||||
private volatile boolean created;
|
||||
private final Object closeLock = new Object();
|
||||
|
||||
/*
|
||||
* The implementation of this DatagramSocket.
|
||||
|
@ -292,6 +293,9 @@ public class DatagramSocket implements java.io.Closeable {
|
|||
// create a datagram socket.
|
||||
boolean multicast = (this instanceof MulticastSocket);
|
||||
this.impl = createImpl(multicast);
|
||||
// creates the udp socket
|
||||
impl.create();
|
||||
created = true;
|
||||
this.oldImpl = checkOldImpl(impl);
|
||||
if (bindaddr != null) {
|
||||
try {
|
||||
|
@ -392,20 +396,27 @@ public class DatagramSocket implements java.io.Closeable {
|
|||
} else {
|
||||
impl = DefaultDatagramSocketImplFactory.createDatagramSocketImpl(multicast);
|
||||
}
|
||||
// creates a udp socket
|
||||
impl.create();
|
||||
return impl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the {@code DatagramSocketImpl} attached to this socket.
|
||||
* Return the {@code DatagramSocketImpl} attached to this socket,
|
||||
* creating the socket if not already created.
|
||||
*
|
||||
* @return the {@code DatagramSocketImpl} attached to that
|
||||
* DatagramSocket
|
||||
* @throws SocketException never thrown
|
||||
* @throws SocketException if creating the socket fails
|
||||
* @since 1.4
|
||||
*/
|
||||
DatagramSocketImpl getImpl() throws SocketException {
|
||||
final DatagramSocketImpl getImpl() throws SocketException {
|
||||
if (!created) {
|
||||
synchronized (this) {
|
||||
if (!created) {
|
||||
impl.create();
|
||||
created = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return impl;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue