Skip to content

Commit 69645fd

Browse files
committed
8361972: Clarify the condition of System.console() about standard input/output
Reviewed-by: smarks, jlu, joehw
1 parent 23670fd commit 69645fd

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

src/java.base/share/classes/java/io/Console.java

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,20 @@
3838
* Methods to access the character-based console device, if any, associated
3939
* with the current Java virtual machine.
4040
*
41-
* <p> Whether a virtual machine has a console is dependent upon the
41+
* <p> Whether a virtual machine's console exists is dependent upon the
4242
* underlying platform and also upon the manner in which the virtual
4343
* machine is invoked. If the virtual machine is started from an
4444
* interactive command line without redirecting the standard input and
45-
* output streams then its console will exist and will typically be
45+
* output streams, then its console will generally exist and will be
4646
* connected to the keyboard and display from which the virtual machine
47-
* was launched. If the virtual machine is started automatically, for
48-
* example by a background job scheduler, then it may not
49-
* have a console.
47+
* was launched. If the standard input or standard output have been
48+
* redirected (for example, to a file or to a pipe), or if the virtual
49+
* machine was started from a background job scheduler, the console
50+
* will not exist.
5051
* <p>
51-
* If this virtual machine has a console then it is represented by a
52-
* unique instance of this class which can be obtained by invoking the
53-
* {@link java.lang.System#console()} method. If no console device is
54-
* available then an invocation of that method will return {@code null}.
52+
* If the console exists, then it is represented by a unique instance of this
53+
* class which can be obtained by invoking the {@link System#console()} method.
54+
* If the console does not exist, that method will return {@code null}.
5555
* <p>
5656
* Read and write operations are synchronized to guarantee the atomic
5757
* completion of critical operations; therefore invoking methods
@@ -535,18 +535,14 @@ public Charset charset() {
535535
/**
536536
* {@return {@code true} if the {@code Console} instance is a terminal}
537537
* <p>
538-
* This method returns {@code true} if the console device, associated with the current
539-
* Java virtual machine, is a terminal, typically an interactive command line
540-
* connected to a keyboard and display.
541-
*
542-
* @implNote The default implementation returns the value equivalent to calling
543-
* {@code isatty(stdin/stdout)} on POSIX platforms, or whether standard in/out file
544-
* descriptors are character devices or not on Windows.
538+
* This method always returns {@code true}, since {@link System#console()}
539+
* provides a {@code Console} instance only when both standard input and
540+
* output are unredirected, that is, when running in an interactive terminal.
545541
*
546542
* @since 22
547543
*/
548544
public boolean isTerminal() {
549-
return istty;
545+
return true;
550546
}
551547

552548
private static UnsupportedOperationException newUnsupportedOperationException() {

0 commit comments

Comments
 (0)