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.
- csr of
-
JDK-8361613 System.console() should only be available for interactive terminal
-
- In Progress
-