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

Michael McMahon michael.x.mcmahon at oracle.com
Fri Jul 22 03:02:30 PDT 2011


There seems to be only a couple of places where IOException 
(specifically) is thrown
in the networking code and it can't occur in this code path as far as I 
can see.
Perhaps that wasn't always the case, which could explain why the unusual 
construction exists.
So, the simplification suggested below seems reasonable.

- Michael.

On 21/07/11 23:54, Brad Wetmore wrote:
> Kurchi,
>
> Please have an additional reviewer for the networking portion of this, 
> but in doing a quick look, I believe the point of the two catches is 
> to make sure that any IOException that isn't already a SocketException 
> (SocketException is a subclass of IOException) is rebranded to 
> SocketException.
>
> If these internal methods are guaranteed to only throw SocketExeptions 
> (and it looks like it), then you can simplify this code to:
>
>     public DatagramSocket() throws SocketException {
>          createImpl();
>          bind(new InetSocketAddress(0));
>     }
>
> bind throws SocketException, InetSocketAddress(int) only throws a IAE 
> (a RuntimeException).
>
> Brad
>
>
>
>
> On 7/21/2011 3:05 PM, Kurchi Hazra wrote:
>> Hi,
>>
>> Due to a recent update in javac to issue a warning on detecting
>> unreachable code, the following warning started showing up in the jdk
>> networking code:
>> ../../../src/share/classes/java/net/DatagramSocket.java:183: warning:
>> unreachable catch clause.
>>
>> This fix aims at removing this warning by removing the IOException. On
>> inspection, it was found that currently, the native code does not throw
>> any IOException.
>>
>> The fix involves updates in:
>> jdk/src/share/classes/java/net/DatagramSocket.java
>>
>>
>> Webrev: http://cr.openjdk.java.net/~chegar/7035556/webrev.00/
>>
>> Thanks,
>> -Kurchi




More information about the net-dev mailing list