RFR: 8264200: java/nio/channels/DatagramChannel/SRTest.java fails intermittently [v2]

Conor Cleary ccleary at openjdk.java.net
Tue Apr 6 16:53:26 UTC 2021


On Tue, 6 Apr 2021 16:48:23 GMT, Conor Cleary <ccleary at openjdk.org> wrote:

>> test/jdk/java/nio/channels/DatagramChannel/SRTest.java line 195:
>> 
>>> 193:                 DatagramPacket dp = new DatagramPacket(buf, buf.length);
>>> 194:                 ds.receive(dp);
>>> 195:                 String received = new String(dp.getData(), US_ASCII);
>> 
>> That's not quite correct, you need to take into account the offset and length of the received data.
>
> Ah... good spot, this results in a needlessly long string.

Changing to `String received = new String(dp.getData(), 0, DATA_STRING.length(), US_ASCII);` seems to correct the issue, using a constant `DATA_STRING`

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

PR: https://git.openjdk.java.net/jdk/pull/3354


More information about the nio-dev mailing list