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
    • minimal
    • This is a doc change only. Other JDK implementations could provide ones that return non-null for redirected System.console(), but I expect the possibility is minimal, possibly none.
    • 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.

      Specification

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

      @@ -43,12 +43,13 @@
         * machine is invoked.  If the virtual machine is started from an
         * interactive command line without redirecting the standard input and
         * output streams then its console will exist and will typically be
         * connected to the keyboard and display from which the virtual machine
         * was launched.  If the virtual machine is started automatically, for
      -  * example by a background job scheduler, then it may not
      -  * have a console.
      +  * example by a background job scheduler, then it may not have a
      +  * console. Regardless of how the virtual machine was created, it may 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
         * unique instance of this class which can be obtained by invoking the
         * {@link java.lang.System#console()} method.  If no console device is
         * available then an invocation of that method will return {@code null}.

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

              Created:
              Updated: