mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
8287541: Files.writeString fails to throw IOException for charset "windows-1252"
Reviewed-by: iris, bpb, alanb, jpai, lancea, aturbanov
This commit is contained in:
parent
a9b9831f2a
commit
6fb84e2c91
2 changed files with 11 additions and 18 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue