11Null-checking ` System.console() ` is not a reliable way to detect if the console
22is connected to a terminal.
33
4- See
4+ See JDK 22
55[ Release Note: JLine As The Default Console Provider] ( https://bugs.openjdk.org/browse/JDK-8309155 ) :
66
77> ` System.console() ` now returns a ` Console ` object when the standard streams
1515> A new method ` Console.isTerminal() ` has been added to test if console is
1616> connected to a terminal.
1717
18+ and JDK 25 release note
19+ [ Release Note: Default Console Implementation No Longer Based On JLine] ( https://bugs.openjdk.org/browse/JDK-8351576 ) :
20+
21+ > The default Console obtained via ` System.console() ` is no longer based on
22+ > JLine. Since JDK 20, the JDK has included a JLine-based Console
23+ > implementation, offering a richer user experience and better support for
24+ > virtual terminal environments, such as IDEs. This implementation was initially
25+ > opt-in via a system property in JDK 20 and JDK 21 and became the default in
26+ > JDK 22. However, maintaining the JLine-based Console proved challenging. As a
27+ > result, in JDK 25, it has reverted to being opt-in, as it was in JDK 20 and
28+ > JDK 21.
29+
1830To prepare for this change while remaining compatible with JDK versions prior to
1931JDK 22, consider using reflection to call ` Console#isTerminal ` on JDK versions
2032that support it:
@@ -23,7 +35,7 @@ that support it:
2335 @SuppressWarnings (" SystemConsoleNull" ) // https://errorprone.info/bugpattern/SystemConsoleNull
2436 private static boolean systemConsoleIsTerminal() {
2537 Console systemConsole = System . console();
26- if (Runtime . version(). feature() < 22 ) {
38+ if (Runtime . version(). feature() < 22 || systemConsole == null ) {
2739 return systemConsole != null ;
2840 }
2941 try {
0 commit comments