Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapt new behavior of System.console() since JDK22 #68

Closed
Eng-Fouad opened this issue Mar 30, 2024 · 0 comments · Fixed by #69
Closed

Adapt new behavior of System.console() since JDK22 #68

Eng-Fouad opened this issue Mar 30, 2024 · 0 comments · Fixed by #69

Comments

@Eng-Fouad
Copy link
Contributor

Eng-Fouad commented Mar 30, 2024

Since JDK22:

In JDK 22, System.console() has been changed to return a Console with enhanced editing features that improve the experience of programs that use the Console API. In addition, System.console() now returns a Console object when the standard streams are redirected or connected to a virtual terminal. Prior to JDK 22, System.console() instead returned null for these cases. This change may impact code that checks the return from System.console() to test if the JVM is connected to a terminal. If required, the -Djdk.console=java.base flag will restore the old behavior where the console is only returned when it is connected to a terminal. Starting JDK 22, one could also use the new Console.isTerminal() method to test if the console is connected to a terminal.

So, this check:

//if console != null its a native terminal, not redirects etc
if(System.console() != null)
return new WinSysTerminal(name, nativeSignals);
else {
return new WinExternalTerminal(name, type, (in == null) ? System.in : in,
(out == null) ? System.out : out);
}

should be changed to:

if (System.console() != null && System.console().isTerminal())

However, isTerminal() is a new method in JDK22. Alternatively, access the private static method Console::istty() isTerminal via reflection.


Note: Jansi crashes the JVM on initializing org.fusesource.jansi.AnsiConsole when System.console().isTerminal() is false. Related: quarkusio/quarkus#39575

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant