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

Andrey Turbanov aturbanov at openjdk.java.net
Sat Jun 4 11:30:16 UTC 2022


On Fri, 3 Jun 2022 16:48:46 GMT, Naoto Sato <naoto at openjdk.org> wrote:

> The code path calls `String.getBytesNoRepl()`, but it blindly replaces unmappable characters with replacements if the encoder is an `ArrayEncoder`. Changed only to do so if `doReplace` is `true` in `String.encodeWithEncoder()`.

src/java.base/share/classes/java/lang/String.java line 849:

> 847:         int en = scale(len, ce.maxBytesPerChar());
> 848:         // fastpath with ArrayEncoder implies `doReplace`.
> 849:         if (ce instanceof ArrayEncoder ae && doReplace) {

Wouldn't it be more readable (and perphaps faster) if we do check boolean flag first?

-------------

PR: https://git.openjdk.java.net/jdk/pull/9019


More information about the nio-dev mailing list