RFR: 8355371: NegativeArraySizeException in print methods in IO or System.console() in JShell [v2]

Tatsunori Uchino duke at openjdk.org
Wed Apr 30 23:22:16 UTC 2025


> This PR will fix not only JDK-8355371 but also JDK-8354910. I chose the more serious one.
> 
> Note: according to JEP-512 (JDK-8344699), java.io.IO is going to stop using System.console().
> I confirmed it by checking out and building https://github.com/openjdk/jdk/pull/24438. (in that PR, the bug does not occur in `IO.print(ln)`)
> 
> Before (Temurin 24):
> 
> 
> jshell> IO.println("a".repeat(128))
> Exception in thread "output reader" java.lang.NegativeArraySizeException: -128
> |  State engine terminated.     at jdk.jshell/jdk.jshell.execution.impl.ConsoleImpl$ConsoleOutputStream.readCharsOrNull(ConsoleImpl.java:486)
> 
>         at jdk.jshell/jdk.jshell.execution.impl.ConsoleImpl$ConsoleOutputStream.write(ConsoleImpl.java:402)
>         at java.base/java.io.OutputStream.write(OutputStream.java:167)
> |  Restore definitions with: /reload -restore
>         at java.base/java.io.OutputStream.write(OutputStream.java:124)
>         at jdk.jshell/jdk.jshell.execution.DemultiplexInput.run(DemultiplexInput.java:74)
> 
> jshell> IO.println("ドラえもん")
> ￉←えツモ
> 
> jshell> System.console().writer().println("a".repeat(128))
> Exception in thread "output reader" java.lang.NegativeArraySizeException: -128
>         at jdk.jshell/jdk.jshell.execution.impl.ConsoleImpl$ConsoleOutputStream.readCharsOrNull(ConsoleImpl.java:486)
> |  State engine terminated.
>         at jdk.jshell/jdk.jshell.execution.impl.ConsoleImpl$ConsoleOutputStream.write(ConsoleImpl.java:402)
>         at java.base/java.io.OutputStream.write(OutputStream.java:167)
> |  Restore definitions with: /reload -restore   at java.base/java.io.OutputStream.write(OutputStream.java:124)
> 
>         at jdk.jshell/jdk.jshell.execution.DemultiplexInput.run(DemultiplexInput.java:74)
> 
> jshell> System.console().writer().println("ドラえもん")
> ￉←えツモ
> 
> 
> After (master & without https://github.com/openjdk/jdk/pull/24438):
> 
> 
> jshell> IO.println("a".repeat(128))
> aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
> 
> jshell> IO.println("ドラえもん")
> ドラえもん
> 
> jshell> System.console().writer().println("a".repeat(128))
> aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
> 
> jshell> System.console().writer().println("ドラえもん")
> ドラえもん
> 
> 
> I don't know how to prepare the template other PRs use or whether outsiders like me may create a PR.

Tatsunori Uchino has updated the pull request incrementally with one additional commit since the last revision:

  Escape katakana

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

Changes:
  - all: https://git.openjdk.org/jdk/pull/24897/files
  - new: https://git.openjdk.org/jdk/pull/24897/files/bf0c454a..7225a190

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=24897&range=01
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=24897&range=00-01

  Stats: 1 line in 1 file changed: 0 ins; 0 del; 1 mod
  Patch: https://git.openjdk.org/jdk/pull/24897.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/24897/head:pull/24897

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


More information about the kulla-dev mailing list