mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 15:24:43 +02:00
8295803: Console should be usable in jshell and other environments
Reviewed-by: jlaskey, alanb
This commit is contained in:
parent
5d4c71c8bd
commit
8a9911ef17
17 changed files with 673 additions and 23 deletions
|
@ -29,6 +29,7 @@ import java.io.*;
|
|||
import java.nio.*;
|
||||
import java.nio.charset.*;
|
||||
import java.util.Arrays;
|
||||
import jdk.internal.access.SharedSecrets;
|
||||
|
||||
/**
|
||||
* A utility class for reading passwords
|
||||
|
@ -51,13 +52,15 @@ public class Password {
|
|||
byte[] consoleBytes = null;
|
||||
|
||||
try {
|
||||
// Use the new java.io.Console class
|
||||
// Only use Console if `in` is the initial System.in
|
||||
Console con;
|
||||
if (!isEchoOn && in == System.in && ((con = System.console()) != null)) {
|
||||
if (!isEchoOn &&
|
||||
in == SharedSecrets.getJavaLangAccess().initialSystemIn() &&
|
||||
((con = System.console()) != null)) {
|
||||
consoleEntered = con.readPassword();
|
||||
// readPassword returns "" if you just print ENTER,
|
||||
// readPassword returns "" if you just press ENTER with the built-in Console,
|
||||
// to be compatible with old Password class, change to null
|
||||
if (consoleEntered != null && consoleEntered.length == 0) {
|
||||
if (consoleEntered == null || consoleEntered.length == 0) {
|
||||
return null;
|
||||
}
|
||||
consoleBytes = convertToBytes(consoleEntered);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue