8357993: Use "stdin.encoding" for reading System.in with InputStreamReader/Scanner [hotspot]

Reviewed-by: cjplummer, sspitsyn
This commit is contained in:
Volkan Yazici 2025-06-06 06:53:10 +00:00
parent e918a59b1d
commit bb2611ad43
4 changed files with 13 additions and 9 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2005, 2021, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2005, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -28,6 +28,7 @@ import sun.jvm.hotspot.*;
import sun.jvm.hotspot.debugger.*; import sun.jvm.hotspot.debugger.*;
import java.io.*; import java.io.*;
import java.nio.charset.Charset;
import java.util.*; import java.util.*;
public class CLHSDB { public class CLHSDB {
@ -106,8 +107,8 @@ public class CLHSDB {
}; };
BufferedReader in = Charset charset = Charset.forName(System.getProperty("stdin.encoding"), Charset.defaultCharset());
new BufferedReader(new InputStreamReader(System.in)); BufferedReader in = new BufferedReader(new InputStreamReader(System.in, charset));
CommandProcessor cp = new CommandProcessor(di, in, System.out, System.err); CommandProcessor cp = new CommandProcessor(di, in, System.out, System.err);
cp.run(true); cp.run(true);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -27,6 +27,7 @@ package jdk.jfr.internal.jfc.model;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.nio.charset.Charset;
public final class UserInterface { public final class UserInterface {
@ -40,7 +41,8 @@ public final class UserInterface {
public String readLine() throws AbortException { public String readLine() throws AbortException {
try { try {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); Charset charset = Charset.forName(System.getProperty("stdin.encoding"), Charset.defaultCharset());
BufferedReader br = new BufferedReader(new InputStreamReader(System.in, charset));
String line = br.readLine(); String line = br.readLine();
if (line == null || line.equalsIgnoreCase("Q")) { if (line == null || line.equalsIgnoreCase("Q")) {
println(); println();

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2007, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -60,7 +60,8 @@ public class attach010Agent00 extends AbstractJarAgent {
FileInputStream newInputStream = new FileInputStream(inStreamFileName); FileInputStream newInputStream = new FileInputStream(inStreamFileName);
System.setIn(newInputStream); System.setIn(newInputStream);
BufferedReader inputStreamReader = new BufferedReader(new InputStreamReader(System.in)); BufferedReader inputStreamReader = new BufferedReader(new InputStreamReader(
System.in, System.getProperty("stdin.encoding")));
int readValue = Integer.parseInt(inputStreamReader.readLine()); int readValue = Integer.parseInt(inputStreamReader.readLine());
if (readValue != valueToWrite) { if (readValue != valueToWrite) {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2001, 2024, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2001, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -173,7 +173,7 @@ public final class BindServer {
} }
BufferedReader stdIn = new BufferedReader( BufferedReader stdIn = new BufferedReader(
new InputStreamReader(System.in)); new InputStreamReader(System.in, System.getProperty("stdin.encoding")));
try (ListeningThread listeningThread = new ListeningThread(this)) { try (ListeningThread listeningThread = new ListeningThread(this)) {
listeningThread.bind(); listeningThread.bind();
listeningThread.start(); listeningThread.start();