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.
% 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.