Code Review Request: 7035556 DatagramSocket.java:183: warning: unreachable catch clause

Kurchi Hazra kurchi.subhra.hazra at oracle.com
Fri Jul 22 10:31:52 PDT 2011


Hi,

   I changed the implementation according to Brad's comments. I am 
reposting the output of hg diff 
src/share/classes/java/net/DatagramSocket.java since I don't have an 
openjdk account:

bash-3.00$ hg diff src/share/classes/java/net/DatagramSocket.java
diff --git a/src/share/classes/java/net/DatagramSocket.java 
b/src/share/classes/java/net/DatagramSocket.java
--- a/src/share/classes/java/net/DatagramSocket.java
+++ b/src/share/classes/java/net/DatagramSocket.java
@@ -176,13 +176,7 @@ class DatagramSocket implements java.io.
      public DatagramSocket() throws SocketException {
          // create a datagram socket.
          createImpl();
-        try {
-            bind(new InetSocketAddress(0));
-        } catch (SocketException se) {
-            throw se;
-        } catch(IOException e) {
-            throw new SocketException(e.getMessage());
-        }
+        bind(new InetSocketAddress(0));
      }


Thanks,
Kurchi



On 7/22/2011 7:25 AM, Michael McMahon wrote:
> On 22/07/11 14:55, Alan Bateman wrote:
>> Michael McMahon wrote:
>>> But, bind() already closes the impl internally before throwing the 
>>> exception.
>> I was wondering about that and whether this is a bug. Suppose someone 
>> creates an unbound DatagramSocket and then attempts to bind it to a 
>> port. If the bind fails (say port already in use) then it may be 
>> surprising that they can't retry with a different port.  Should this 
>> be specified? I see there are cases such as the security exception 
>> where it doesn't the close the impl.
>>
>> -Alan.
> It doesn't seem to be specified either way, though it does seem to be 
> inconsistent.
> I'd be wary about changing the behaviour though
> unless there was a strong justification (more than a compiler warning :) )
>
> - Michael.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/net-dev/attachments/20110722/58388123/attachment.html 


More information about the net-dev mailing list