Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8324977

Console implementations behave differently in regard to EOF

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 23
    • core-libs
    • None
    • aarch64
    • os_x

      I'm experimenting with the following program on macOS 14.2.1 (23C71):

      % cat MyClass.java
      public class MyClass {
          public static void main(String... args) throws Throwable {
              System.out.println(System.console().readLine("?"));
          }
      }

      Here's what happens when running that program and CTRL+D is pressed right after the prompt is issued:

      % ./build/macosx-aarch64/images/jdk/bin/java MyClass.java
      ?
      null

      Now, if the fallback console implementation is used, the behaviour is slightly different; note how there's no newline between ? and null:

      % ./build/macosx-aarch64/images/jdk/bin/java -Djdk.console=java.base MyClass.java
      ?null

      In addition to that, CTRL+D always works in the fallback case, but in the normal case, it only works if the input is empty.

            naoto Naoto Sato
            prappo Pavel Rappo
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: