array length changes in openjdk array length changes in openjdk arrays arrays

array length changes in openjdk


This is most likely an issue with the bytes and the system charset. The documentation explicitly says:

The behavior of this constructor when the given bytes are not valid in the default charset is unspecified.

You can circumvent this by explicitly providing the correct charset:

new String(buffer, 70, 16, StandardCharsets.UTF_8)


You are creating the new String using byte[] array without specifying the Charset. Thus my guess is that system default charset got changed and you see the behaviour changes. I'd suggest to always specify the charset explicitly. For example:

return new String(buffer, 70, 16, "UTF-8");