RFR: 8356165: System.in in jshell replace supplementary characters with ??

Tatsunori Uchino duke at openjdk.org
Thu May 8 15:23:51 UTC 2025


On Wed, 7 May 2025 06:44:54 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:

> When reading from `System.in` in a JShell snippet, JShell first reads the whole line (getting a `String`), and then converts this characters from this `String` to bytes on demand. But, it does not convert multi-surrogate code points correctly, it tries to convert each surrogate separately, which cannot work.
> 
> The proposal herein is to, when the current character is a high surrogate, peek at the next character, and if it is a low surrogate, convert both the high and low surrogates to bytes together.

test/langtools/jdk/jshell/InputUITest.java line 53:

> 51:         doRunTest((inputSink, out) -> {
> 52:             inputSink.write("new String(System.in.readNBytes(4))\n\uD83D\uDE03\n");
> 53:             waitOutput(out, "\"\uD83D\uDE03\"");

Can the current implementation pass the following test?


-            inputSink.write("new String(System.in.readNBytes(4))\n\uD83D\uDE03\n");
-            waitOutput(out, ""\uD83D\uDE03"");
+            inputSink.write("new String(System.in.readNBytes(5))\n\uD83D\uDE031\n");
+            waitOutput(out, ""\uD83D\uDE031"");

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

PR Review Comment: https://git.openjdk.org/jdk/pull/25079#discussion_r2079939731


More information about the kulla-dev mailing list