RFR: 8293696: java/nio/channels/DatagramChannel/SelectWhenRefused.java fails with "Unexpected wakeup" [v5]
Daniel Fuchs
dfuchs at openjdk.org
Wed Nov 2 17:13:47 UTC 2022
On Wed, 2 Nov 2022 16:57:41 GMT, Darragh Clarke <duke at openjdk.org> wrote:
>> test/jdk/java/nio/channels/DatagramChannel/SelectWhenRefused.java line 147:
>>
>>> 145: ByteBuffer buf = ByteBuffer.allocate(100);
>>> 146: SocketAddress sa = datagramChannel.receive(buf);
>>> 147: String message = new String(buf.array());
>>
>> You can't really use new String(buf.array()) here because you will read past the bytes that have been received. Also keep in mind that after receiving the position of the BB will be *at the end* of the message.
>
> Adding `buf.flip()` between 146 and 147 should be enough to address this right?
No because buf.array() always return the same array of 100 bytes that the buffer wraps, regardless of the byte buffer position and limit.
-------------
PR: https://git.openjdk.org/jdk/pull/10851
More information about the nio-dev
mailing list