On Tue, 28 Jun 2022 16:54:46 GMT, Bill Huang <[email protected]> wrote:

>> test/jdk/java/net/DatagramSocket/InterruptibleDatagramSocket.java line 111:
>> 
>>> 109:         }
>>> 110:         try (DatagramSocket s = DatagramChannel.open().socket()) {
>>> 111:             System.out.println("Testing interrrupt of DatagramChannel 
>>> socket " +
>> 
>> I just noticed that this System out will return a null address:
>> Testing interrrupt of DatagramChannel socket receive on endpoint null
>> This shows an anomalies between DatagramChannel and DatagramSocket in that 
>> an explicit bind is usually required for DC. In this case when the receive 
>> is invoked there will be an implicit bind to wildcard and ephemeral port  
>> ... The test could be changed to invoke bind(null) on the created DC, maybe 
>> as follows:
>> 
>>        try (DatagramChannel dc = DatagramChannel.open().bind(null)) {
>>             System.out.println("Testing interrrupt of DatagramChannel socket 
>> " +
>>                     "receive on endpoint " + dc.getLocalAddress());
>>             test(dc.socket(), true);
>>         }
>> 
>> This will give the informed output
>> Testing interrrupt of DatagramChannel socket receive on endpoint 
>> /[0:0:0:0:0:0:0:0]:54572
>> 
>> which trivially highlight a triple r in interrrupt
>
> @msheppar Thank you for pointing out the issue and providing a fix. I noticed 
> the null reference on my system as well. I didn't pay attention to it because 
> it might not be related to the initial failure for its interruptibility in 
> DC. But I totally agree that we should have more meaningful messages in the 
> log to avoid confusion. In your code, the socket address is determined upon 
> binding operation and it will be bound to the socket later. I think we can 
> have a more consolidated code as below, which surrounds the socket creation 
> in a try-resource statement.
> 
> try (DatagramSocket s = DatagramChannel.open().bind(null).socket()) {
>         System.out.println("Testing interrupt of DatagramChannel socket " +
>                 "receive on endpoint " + s.getLocalSocketAddress());
>         test(s, true);
> }

looks fine to me

-------------

PR: https://git.openjdk.org/jdk/pull/9278

Reply via email to