Skip to content

[1.x] Migrate all usages of System.console == null #7843

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

Merged
merged 1 commit into from
Oct 29, 2024

Conversation

Friendseeker
Copy link
Member

@Friendseeker Friendseeker commented Oct 29, 2024

Issue

nartamonov pointed out that JDK 22 changed the behavior of System.console in #7580.

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.

sbt assumes the old behavior of System.console and use System.console == null to check if connection to terminal exists, causing issue like #7580 and #7841

Solution

We reflectively call Console.isTerminal() if it exists, otherwise fall back to JDK 8 System.console == null comparison.

Closes #7841
Closes #7842

Copy link
Member

@eed3si9n eed3si9n left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@adpi2 adpi2 merged commit 4835812 into sbt:1.10.x Oct 29, 2024
10 checks passed
@Friendseeker Friendseeker deleted the jdk-console-migrate branch October 29, 2024 16:18
lihaoyi pushed a commit to com-lihaoyi/mill that referenced this pull request Dec 27, 2024
…2 support (#4178)

JDK 22 introduced some changes to the method `System.console()`:

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

Mill assumes the old behavior of `System.console` and use
`System.console() != null` to check if we have interactive console,
causing issue like #4161.

This PR added universal availability check for an interactive console,
compatible with JDK < 22 and later.

SBT made similar changes in sbt/sbt#7843.

Closes #4161

---------

Co-authored-by: Nikolay Artamonov <n.artamonov@sigma-it.ru>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[1.x] [JDK 22+] Migrate all usage of System.console == null [1.x] [JDK 22+] [Windows] sbtn spawns dumb terminal
3 participants