RFR: 8347756: Re-evaluate the java/net/DatagramSocket/InterruptibleDatagramSocket.java test

Daniel Fuchs dfuchs at openjdk.org
Wed Jan 15 14:51:38 UTC 2025


On Wed, 15 Jan 2025 13:21:30 GMT, Jaikiran Pai <jpai at openjdk.org> wrote:

> Can I please get a review of this test-only change which updates the `test/jdk/java/net/DatagramSocket/InterruptibleDatagramSocket.java` to match the specified behaviour of `DatagramSocket.receive()` method?
> 
> This test was introduced in Java 14 (https://bugs.openjdk.org/browse/JDK-8233018) and that version of Java through Java 18, behave differently when a DatagramSocket associated with a DatagramChannel, when blocked in a receive() is interrupted. In those versions, a `SocketException` gets thrown with `ClosedByInterruptException` as the cause of that `SocketException`. 
> 
> Starting Java 19, the specification of DatagramSocket.receive() has been updated to clarify the expectations of this scenario. Given those updates, the DatagramSocket.receive() is expected to throw a (top level) `ClosedByInterruptException` when associated with a `DatagramChannel`.
> 
> The change in this PR updates the test code to no longer expect a `SocketException` to contain the `ClosedByInterruptException`. With this change the test continues to pass both with platform threads as well as virtual threads. The test will no longer be skipped when the main() is launched through a virtual thread.

test/jdk/java/net/DatagramSocket/InterruptibleDatagramSocket.java line 87:

> 85:                 throw e;
> 86:             }
> 87:             System.out.println("Got expected: " + e);

Should the check on the exception be a little more focused than blindly accepting any SocketException when the socket is interruptible?

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

PR Review Comment: https://git.openjdk.org/jdk/pull/23135#discussion_r1916790398


More information about the net-dev mailing list