RFR: 8288589: Files.readString ignores encoding errors for UTF-16 [v6]

Naoto Sato naoto at openjdk.org
Wed Jun 22 17:46:58 UTC 2022


> This is a regression caused by the fix to [JDK-8286287](https://bugs.openjdk.org/browse/JDK-8286287), which assumed the method `String.decodeWithDecoder()` was only invoked with cs.REPLACE mode based on the comment "should not happen". Possibly this refers to the `String(byte[], int, int, Charset)` constructor, which specifically mentions the `REPLACE` mode. However, the method is invoked with `String.newStringNoRepl()` and it should NOT replace the malformed input (duh!). The fix is to throw an `Error` for the former case as before the regression, and `CharacterCodingException` for the latter via an `IllegalArgumentException`.
> In fact, `Files.readString()` stopped throwing a `MalformedInputException` since JDK17 with the fix to JDK-8259842, which started throwing an `Error`.

Naoto Sato has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains seven additional commits since the last revision:

 - Leave the log files in the current directory
 - Merge branch 'master' into JDK-8288589
 - Moved `@Test` annotations
 - Refined the test, adding more variations.
 - Adding a test case in ReadWriteString.java
 - Added c2b test
 - 8288589: Files.readString ignores encoding errors for UTF-16

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

Changes:
  - all: https://git.openjdk.org/jdk/pull/9193/files
  - new: https://git.openjdk.org/jdk/pull/9193/files/864806ef..09cdf5e7

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=9193&range=05
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=9193&range=04-05

  Stats: 4620 lines in 234 files changed: 2654 ins; 1073 del; 893 mod
  Patch: https://git.openjdk.org/jdk/pull/9193.diff
  Fetch: git fetch https://git.openjdk.org/jdk pull/9193/head:pull/9193

PR: https://git.openjdk.org/jdk/pull/9193


More information about the core-libs-dev mailing list