8209576: java.nio.file.Files.writeString writes garbled UTF-16 instead of UTF-8

Reviewed-by: sherman
This commit is contained in:
Joe Wang 2018-08-20 10:11:26 -07:00
parent 0f4805ef4c
commit 0afc1b41c3
2 changed files with 86 additions and 14 deletions

View file

@ -1068,7 +1068,7 @@ class StringCoding {
byte[] val = s.value();
byte coder = s.coder();
if (cs == UTF_8) {
if (isASCII(val)) {
if (coder == LATIN1 && isASCII(val)) {
return val;
}
return encodeUTF8(coder, val, false);