Skip to content

Commit bb2611a

Browse files
committed
8357993: Use "stdin.encoding" for reading System.in with InputStreamReader/Scanner [hotspot]
Reviewed-by: cjplummer, sspitsyn
1 parent e918a59 commit bb2611a

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/CLHSDB.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2005, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -28,6 +28,7 @@
2828
import sun.jvm.hotspot.debugger.*;
2929

3030
import java.io.*;
31+
import java.nio.charset.Charset;
3132
import java.util.*;
3233

3334
public class CLHSDB {
@@ -106,8 +107,8 @@ public void reattach() {
106107
};
107108

108109

109-
BufferedReader in =
110-
new BufferedReader(new InputStreamReader(System.in));
110+
Charset charset = Charset.forName(System.getProperty("stdin.encoding"), Charset.defaultCharset());
111+
BufferedReader in = new BufferedReader(new InputStreamReader(System.in, charset));
111112
CommandProcessor cp = new CommandProcessor(di, in, System.out, System.err);
112113
cp.run(true);
113114

src/jdk.jfr/share/classes/jdk/jfr/internal/jfc/model/UserInterface.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -27,6 +27,7 @@
2727
import java.io.BufferedReader;
2828
import java.io.IOException;
2929
import java.io.InputStreamReader;
30+
import java.nio.charset.Charset;
3031

3132
public final class UserInterface {
3233

@@ -40,7 +41,8 @@ public void println(String text) {
4041

4142
public String readLine() throws AbortException {
4243
try {
43-
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
44+
Charset charset = Charset.forName(System.getProperty("stdin.encoding"), Charset.defaultCharset());
45+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in, charset));
4446
String line = br.readLine();
4547
if (line == null || line.equalsIgnoreCase("Q")) {
4648
println();

test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach010/attach010Agent00.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2007, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -60,7 +60,8 @@ protected void agentActions() throws Throwable {
6060
FileInputStream newInputStream = new FileInputStream(inStreamFileName);
6161
System.setIn(newInputStream);
6262

63-
BufferedReader inputStreamReader = new BufferedReader(new InputStreamReader(System.in));
63+
BufferedReader inputStreamReader = new BufferedReader(new InputStreamReader(
64+
System.in, System.getProperty("stdin.encoding")));
6465
int readValue = Integer.parseInt(inputStreamReader.readLine());
6566

6667
if (readValue != valueToWrite) {

test/hotspot/jtreg/vmTestbase/nsk/share/jpda/BindServer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2001, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -173,7 +173,7 @@ private int runIt(String argv[], PrintStream out) {
173173
}
174174

175175
BufferedReader stdIn = new BufferedReader(
176-
new InputStreamReader(System.in));
176+
new InputStreamReader(System.in, System.getProperty("stdin.encoding")));
177177
try (ListeningThread listeningThread = new ListeningThread(this)) {
178178
listeningThread.bind();
179179
listeningThread.start();

0 commit comments

Comments
 (0)