Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8361981

Clarify the condition of System.console() about standard input/output

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Unresolved
    • Icon: P4 P4
    • 26
    • core-libs
    • None
    • behavioral
    • low
    • Hide
      Other JDK implementations could provide ones that return non-null for redirected System.console(), but I expect the possibility is minimal, possibly none. `System.console().isTerminal()` invocation on jshell now returns `true`. It used to return `false` due to the fact that it is the environment in remote process where input/output are redirected.
      Show
      Other JDK implementations could provide ones that return non-null for redirected System.console(), but I expect the possibility is minimal, possibly none. `System.console().isTerminal()` invocation on jshell now returns `true`. It used to return `false` due to the fact that it is the environment in remote process where input/output are redirected.
    • Java API
    • SE

      Summary

      Clarify the condition of System.console() about standard input/output

      Problem

      JDK-8361613 restricts the JLine based Console implementation to return the instance from System.console() only when both standard input and output are attached to the terminal. It is desirable to clarify the java.io.Console specification regarding the Console availability when standard input / output may not be connected to a terminal.

      Solution

      Modify the class description in the java.io.Console where System.console() is mentioned to include the condition about the standard input/output, i.e., a Console will not be available if either standard input or output (or both) is redirected. Also, modify the spec of isTerminal() method to return always true.

      Specification

      Change the last sentence of the second paragraph of the class description of java.io.Console as follows:

         * was launched.  If the virtual machine is started automatically, for
         * example by a background job scheduler, then it may not
      -  * have a console.
      +  * have a console. Regardless of how the virtual machine was created,
      +  * it will not have a console if either the standard input or output
      +  * stream is redirected.
         * <p>
         * If this virtual machine has a console then it is represented by a

      Change the method description of isTerminal() as:

             * {@return {@code true} if the {@code Console} instance is a terminal}
             * <p>
      -      * This method returns {@code true} if the console device, associated with the current
      -      * Java virtual machine, is a terminal, typically an interactive command line
      -      * connected to a keyboard and display.
      -      *
      -      * @implNote The default implementation returns the value equivalent to calling
      -      * {@code isatty(stdin/stdout)} on POSIX platforms, or whether standard in/out file
      -      * descriptors are character devices or not on Windows.
      +      * This method always returns {@code true}, since {@link System#console()}
      +      * provides a {@code Console} instance only when both standard input and
      +      * output are unredirected, that is, when running in an interactive terminal.
             *

            naoto Naoto Sato
            naoto Naoto Sato
            Justin Lu
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: