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

Roger Riggs rriggs at openjdk.java.net
Tue Apr 6 14:38:28 UTC 2021


On Tue, 6 Apr 2021 14:28:37 GMT, Roger Riggs <rriggs at openjdk.org> wrote:

>> The message sent by the writer is "hello" - it only contains ASCII characters, so any of US-ASCII, UTF-8, or ISO-8859-1, which are all compatible with ASCII (meaning: all these encode ASCII chars in the same way) would work.
>> In fact any charset in which "hello" is mappable would work. We simply need to make sure to use the *same charset* when encoding or decoding.
>
> Its case by case, if you don't know how the stream of characters was encoded into a byte stream then you can't reliably decode it back to characters.  For SRTest, it doesn't matter, all the strings I see are ascii.
> But note that String.getBytes() uses a platform dependent encoding. 
> Until the platform encoding is UTF-8, its recommended to use String.getBytes(charset).
> A lot of times UTF-8 is a good guess for operations that convert strings to bytes and back.

As the test is for Datagram send and receive all the data is in byte arrays or equivalent.
The entire test could be written using only byte arrays (no Strings, Charsets or conversions) and omit that possibility of confusion about what the test is doing.
(And there's no need to change anything).

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

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


More information about the nio-dev mailing list