Skip to content

Commit 934d6cb

Browse files
Make DAP implementation to be encoding-neutral (#391)
1 parent d5fc1fd commit 934d6cb

File tree

3 files changed

+12
-20
lines changed

3 files changed

+12
-20
lines changed

com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/ProcessConsole.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public void stop() {
129129
}
130130

131131
private void monitor(InputStream input, PublishSubject<String> subject) {
132-
BufferedReader reader = new BufferedReader(new InputStreamReader(input, encoding));
132+
BufferedReader reader = new BufferedReader(encoding == null ? new InputStreamReader(input) : new InputStreamReader(input, encoding));
133133
final int BUFFERSIZE = 4096;
134134
char[] buffer = new char[BUFFERSIZE];
135135
while (true) {

com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/LaunchRequestHandler.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import java.net.MalformedURLException;
1717
import java.net.URISyntaxException;
1818
import java.nio.charset.Charset;
19-
import java.nio.charset.StandardCharsets;
2019
import java.nio.file.Path;
2120
import java.nio.file.Paths;
2221
import java.util.ArrayList;
@@ -90,23 +89,21 @@ protected CompletableFuture<Response> handleLaunchCommand(Arguments arguments, R
9089
"Failed to launch debuggee VM. Missing mainClass or modulePaths/classPaths options in launch configuration.",
9190
ErrorCode.ARGUMENT_MISSING);
9291
}
93-
if (StringUtils.isBlank(launchArguments.encoding)) {
94-
context.setDebuggeeEncoding(StandardCharsets.UTF_8);
95-
} else {
92+
if (StringUtils.isNotBlank(launchArguments.encoding)) {
9693
if (!Charset.isSupported(launchArguments.encoding)) {
9794
throw AdapterUtils.createCompletionException(
9895
"Failed to launch debuggee VM. 'encoding' options in the launch configuration is not recognized.",
9996
ErrorCode.INVALID_ENCODING);
10097
}
10198
context.setDebuggeeEncoding(Charset.forName(launchArguments.encoding));
99+
if (StringUtils.isBlank(launchArguments.vmArgs)) {
100+
launchArguments.vmArgs = String.format("-Dfile.encoding=%s", context.getDebuggeeEncoding().name());
101+
} else {
102+
// if vmArgs already has the file.encoding settings, duplicate options for jvm will not cause an error, the right most value wins
103+
launchArguments.vmArgs = String.format("%s -Dfile.encoding=%s", launchArguments.vmArgs, context.getDebuggeeEncoding().name());
104+
}
102105
}
103106

104-
if (StringUtils.isBlank(launchArguments.vmArgs)) {
105-
launchArguments.vmArgs = String.format("-Dfile.encoding=%s", context.getDebuggeeEncoding().name());
106-
} else {
107-
// if vmArgs already has the file.encoding settings, duplicate options for jvm will not cause an error, the right most value wins
108-
launchArguments.vmArgs = String.format("%s -Dfile.encoding=%s", launchArguments.vmArgs, context.getDebuggeeEncoding().name());
109-
}
110107
context.setLaunchMode(launchArguments.noDebug ? LaunchMode.NO_DEBUG : LaunchMode.DEBUG);
111108

112109
activeLaunchHandler.preLaunch(launchArguments, context);

com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/JdtSourceLookUpProvider.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2017-2020 Microsoft Corporation and others.
2+
* Copyright (c) 2017-2021 Microsoft Corporation and others.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -17,7 +17,6 @@
1717
import java.io.InputStreamReader;
1818
import java.net.URI;
1919
import java.net.URISyntaxException;
20-
import java.nio.charset.Charset;
2120
import java.nio.file.Files;
2221
import java.nio.file.Paths;
2322
import java.util.HashMap;
@@ -120,11 +119,7 @@ public String[] getFullyQualifiedName(String uri, int[] lines, int[] columns) th
120119
String filePath = AdapterUtils.toPath(uri);
121120
// For file uri, read the file contents directly and pass them to the ast parser.
122121
if (filePath != null && Files.isRegularFile(Paths.get(filePath))) {
123-
Charset cs = (Charset) this.options.get(Constants.DEBUGGEE_ENCODING);
124-
if (cs == null) {
125-
cs = Charset.defaultCharset();
126-
}
127-
String source = readFile(filePath, cs);
122+
String source = readFile(filePath);
128123
parser.setSource(source.toCharArray());
129124
/**
130125
* See the java doc for { @link ASTParser#setResolveBindings(boolean) }.
@@ -293,10 +288,10 @@ private static IClassFile resolveClassFile(String uriString) {
293288
return null;
294289
}
295290

296-
private static String readFile(String filePath, Charset cs) {
291+
private static String readFile(String filePath) {
297292
StringBuilder builder = new StringBuilder();
298293
try (BufferedReader bufferReader =
299-
new BufferedReader(new InputStreamReader(new FileInputStream(filePath), cs))) {
294+
new BufferedReader(new InputStreamReader(new FileInputStream(filePath)))) {
300295
final int BUFFER_SIZE = 4096;
301296
char[] buffer = new char[BUFFER_SIZE];
302297
while (true) {

0 commit comments

Comments
 (0)