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

System.console() should only be available for interactive terminal

XMLWordPrintable

    • behavioral
    • low
    • Hide
      Applications that expect System.console() to return non-null when standard input/output is redirected may be affected. While the current JDK (as of version 25) adopts the new behavior by default, making the risk low, the issue can resurface when a JLine-based console implementation is explicitly specified via the system property -Djdk.console=jdk.internal.le.
      Show
      Applications that expect System.console() to return non-null when standard input/output is redirected may be affected. While the current JDK (as of version 25) adopts the new behavior by default, making the risk low, the issue can resurface when a JLine-based console implementation is explicitly specified via the system property -Djdk.console=jdk.internal.le.
    • Java API
    • JDK

      Summary

      System.console() should return the JVM's Console instance only when both standard input and output are connected to a terminal

      Problem

      The current java.io.Console class description reads:

      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 System.console() method.
      If no console device is available then an invocation of that method will return null.

      Thus, it is up to the implementation to determine under what conditions a Console instance is returned. In recent JDK releases, a JLine-based Console implementation is available, which provides a Console instance even when standard input and/or output is redirected. This behavior can be problematic for password prompts, as users may be unaware of where the prompt is shown or where their input is being sent.

      Solution

      Enforce the rule that System.console() returns null when standard input and/or output is redirected, and a Console instance should not be created in such cases.

      Specification

      N/A. This is a behavioral change only.

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

              Created:
              Updated: