-
Bug
-
Resolution: Fixed
-
P3
-
openjdk8u372
-
b02
-
generic
-
linux
During the 8u backport review of JDK-8287107 this came up. Andrew Hughes pointed out that:
[...] it should be Files.writeString(a, b) => Files.write(a, b.getBytes(StandardCharsets.UTF_8)) rather than Files.writeString(a, b) => Files.write(a, b.getBytes()). Files.writeString(a,b) is a shorthand for Files.writeString(a, b, StandardCharsets.UTF_8), while getBytes() with no arguments will use the platform default character set. This could lead to different behaviour with the default character set is not ASCII or UTF-8.
There are at least 50 occurrences of this pattern in test code:
$ grep -rn 'Files.write(' jdk/test/jdk/internal/platform/ hotspot/test/runtime/containers/ | grep 'getBytes()' | wc -l
50
We should fix this in one sweep.
[...] it should be Files.writeString(a, b) => Files.write(a, b.getBytes(StandardCharsets.UTF_8)) rather than Files.writeString(a, b) => Files.write(a, b.getBytes()). Files.writeString(a,b) is a shorthand for Files.writeString(a, b, StandardCharsets.UTF_8), while getBytes() with no arguments will use the platform default character set. This could lead to different behaviour with the default character set is not ASCII or UTF-8.
There are at least 50 occurrences of this pattern in test code:
$ grep -rn 'Files.write(' jdk/test/jdk/internal/platform/ hotspot/test/runtime/containers/ | grep 'getBytes()' | wc -l
50
We should fix this in one sweep.