Console implementations behave differently in regard to EOF

XMLWordPrintable

    • Type: Bug
    • Resolution: Unresolved
    • Priority: P4
    • tbd
    • Affects Version/s: 23
    • Component/s: 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.

            Assignee:
            Naoto Sato
            Reporter:
            Pavel Rappo
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: