mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 07:14:30 +02:00
8320798: Console read line with zero out should zero out underlying buffer
Reviewed-by: bpb, lancea, joehw, alanb, jpai, mbaesken
This commit is contained in:
parent
3087e14cde
commit
d568562966
2 changed files with 30 additions and 1 deletions
|
@ -42,6 +42,8 @@ import java.nio.charset.CoderResult;
|
|||
import java.nio.charset.CodingErrorAction;
|
||||
import java.nio.charset.IllegalCharsetNameException;
|
||||
import java.nio.charset.UnsupportedCharsetException;
|
||||
import java.util.Arrays;
|
||||
|
||||
import jdk.internal.misc.InternalLock;
|
||||
|
||||
public class StreamDecoder extends Reader {
|
||||
|
@ -271,6 +273,25 @@ public class StreamDecoder extends Reader {
|
|||
return !closed;
|
||||
}
|
||||
|
||||
public void fillZeroToPosition() throws IOException {
|
||||
Object lock = this.lock;
|
||||
if (lock instanceof InternalLock locker) {
|
||||
locker.lock();
|
||||
try {
|
||||
lockedFillZeroToPosition();
|
||||
} finally {
|
||||
locker.unlock();
|
||||
}
|
||||
} else {
|
||||
synchronized (lock) {
|
||||
lockedFillZeroToPosition();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void lockedFillZeroToPosition() {
|
||||
Arrays.fill(bb.array(), bb.arrayOffset(), bb.arrayOffset() + bb.position(), (byte)0);
|
||||
}
|
||||
|
||||
// -- Charset-based stream decoder impl --
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue