< prev index next >
src/java.base/share/classes/java/io/Console.java
Print this page
rev 49849 : [mq]: 8202105
*** 309,321 ****
*/
public char[] readPassword(String fmt, Object ... args) {
char[] passwd = null;
synchronized (writeLock) {
synchronized(readLock) {
- boolean echoWasOn;
try {
! echoWasOn = echo(false);
} catch (IOException x) {
throw new IOError(x);
}
IOError ioe = null;
try {
--- 309,322 ----
*/
public char[] readPassword(String fmt, Object ... args) {
char[] passwd = null;
synchronized (writeLock) {
synchronized(readLock) {
try {
! echoWasOn = echo0();
! restoreEchoOnShutdown = true;
! echo(false);
} catch (IOException x) {
throw new IOError(x);
}
IOError ioe = null;
try {
*** 330,339 ****
--- 331,342 ----
} catch (IOException x) {
if (ioe == null)
ioe = new IOError(x);
else
ioe.addSuppressed(x);
+ } finally {
+ restoreEchoOnShutdown = false;
}
if (ioe != null)
throw ioe;
}
pw.println();
*** 370,379 ****
--- 373,384 ----
private Writer out;
private PrintWriter pw;
private Formatter formatter;
private Charset cs;
private char[] rcb;
+ private boolean restoreEchoOnShutdown;
+ private boolean echoWasOn;
private static native String encoding();
/*
* Sets the console echo status to {@code on} and returns the previous
* console on/off status.
* @param on the echo status to set to. {@code true} for echo on and
*** 384,394 ****
/*
* Returns the current console echo on/off status.
* @return true if the cosole echo is on
*/
private static native boolean echo0() throws IOException;
- private static boolean echoOn;
private char[] readline(boolean zeroOut) throws IOException {
int len = reader.read(rcb, 0, rcb.length);
if (len < 0)
return null; //EOL
--- 389,398 ----
*** 538,549 ****
.registerShutdownHook(0 /* shutdown hook invocation order */,
false /* only register if shutdown is not in progress */,
new Runnable() {
public void run() {
try {
! if (cons != null)
! echo(echoOn);
} catch (IOException x) { }
}
});
} catch (IllegalStateException e) {
// shutdown is already in progress and console is first used
--- 542,553 ----
.registerShutdownHook(0 /* shutdown hook invocation order */,
false /* only register if shutdown is not in progress */,
new Runnable() {
public void run() {
try {
! if (cons != null && cons.restoreEchoOnShutdown)
! echo(cons.echoWasOn);
} catch (IOException x) { }
}
});
} catch (IllegalStateException e) {
// shutdown is already in progress and console is first used
*** 589,600 ****
reader = new LineReader(StreamDecoder.forInputStreamReader(
new FileInputStream(FileDescriptor.in),
readLock,
cs));
rcb = new char[1024];
- try {
- echoOn = echo0();
- } catch (IOException x) {
- echoOn = true;
- }
}
}
--- 593,599 ----
< prev index next >