Merge "Avoid binding a DatagramSocket before setReuseAddress"
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/net/DatagramSocketTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/net/DatagramSocketTest.java
index d9f3d91..e8f8e29 100644
--- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/net/DatagramSocketTest.java
+++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/net/DatagramSocketTest.java
@@ -819,7 +819,7 @@
}
public void test_getReuseAddress() throws Exception {
- DatagramSocket theSocket = new DatagramSocket();
+ DatagramSocket theSocket = new DatagramSocket(null);
theSocket.setReuseAddress(true);
assertTrue("getReuseAddress false when it should be true", theSocket.getReuseAddress());
theSocket.setReuseAddress(false);
diff --git a/luni/src/main/java/java/net/MulticastSocket.java b/luni/src/main/java/java/net/MulticastSocket.java
index 24e66c5..2d8fdd6 100644
--- a/luni/src/main/java/java/net/MulticastSocket.java
+++ b/luni/src/main/java/java/net/MulticastSocket.java
@@ -41,7 +41,9 @@
* @throws IOException if an error occurs.
*/
public MulticastSocket() throws IOException {
+ super((SocketAddress) null);
setReuseAddress(true);
+ bind(null);
}
/**
@@ -51,8 +53,7 @@
* @throws IOException if an error occurs.
*/
public MulticastSocket(int port) throws IOException {
- super(port);
- setReuseAddress(true);
+ this(new InetSocketAddress(Inet6Address.ANY, port));
}
/**
@@ -64,8 +65,11 @@
* @throws IOException if an error occurs.
*/
public MulticastSocket(SocketAddress localAddress) throws IOException {
- super(localAddress);
+ super((SocketAddress) null);
setReuseAddress(true);
+ if (localAddress != null) {
+ bind(localAddress);
+ }
}
/**