8287541: Files.writeString fails to throw IOException for charset "windows-1252"

Reviewed-by: iris, bpb, alanb, jpai, lancea, aturbanov
This commit is contained in:
Naoto Sato 2022-06-08 15:50:06 +00:00
parent a9b9831f2a
commit 6fb84e2c91
2 changed files with 11 additions and 18 deletions

View file

@ -845,7 +845,8 @@ public final class String
CharsetEncoder ce = cs.newEncoder();
int len = val.length >> coder; // assume LATIN1=0/UTF16=1;
int en = scale(len, ce.maxBytesPerChar());
if (ce instanceof ArrayEncoder ae) {
// fastpath with ArrayEncoder implies `doReplace`.
if (doReplace && ce instanceof ArrayEncoder ae) {
// fastpath for ascii compatible
if (coder == LATIN1 &&
ae.isASCIICompatible() &&
@ -856,10 +857,6 @@ public final class String
if (len == 0) {
return ba;
}
if (doReplace) {
ce.onMalformedInput(CodingErrorAction.REPLACE)
.onUnmappableCharacter(CodingErrorAction.REPLACE);
}
int blen = (coder == LATIN1) ? ae.encodeFromLatin1(val, 0, len, ba)
: ae.encodeFromUTF16(val, 0, len, ba);