Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public void stop() {
}

private void monitor(InputStream input, PublishSubject<String> subject) {
BufferedReader reader = new BufferedReader(new InputStreamReader(input, encoding));
BufferedReader reader = new BufferedReader(encoding == null ? new InputStreamReader(input) : new InputStreamReader(input, encoding));
final int BUFFERSIZE = 4096;
char[] buffer = new char[BUFFERSIZE];
while (true) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
Expand Down Expand Up @@ -90,23 +89,21 @@ protected CompletableFuture<Response> handleLaunchCommand(Arguments arguments, R
"Failed to launch debuggee VM. Missing mainClass or modulePaths/classPaths options in launch configuration.",
ErrorCode.ARGUMENT_MISSING);
}
if (StringUtils.isBlank(launchArguments.encoding)) {
context.setDebuggeeEncoding(StandardCharsets.UTF_8);
} else {
if (StringUtils.isNotBlank(launchArguments.encoding)) {
if (!Charset.isSupported(launchArguments.encoding)) {
throw AdapterUtils.createCompletionException(
"Failed to launch debuggee VM. 'encoding' options in the launch configuration is not recognized.",
ErrorCode.INVALID_ENCODING);
}
context.setDebuggeeEncoding(Charset.forName(launchArguments.encoding));
if (StringUtils.isBlank(launchArguments.vmArgs)) {
launchArguments.vmArgs = String.format("-Dfile.encoding=%s", context.getDebuggeeEncoding().name());
} else {
// if vmArgs already has the file.encoding settings, duplicate options for jvm will not cause an error, the right most value wins
launchArguments.vmArgs = String.format("%s -Dfile.encoding=%s", launchArguments.vmArgs, context.getDebuggeeEncoding().name());
}
}

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

activeLaunchHandler.preLaunch(launchArguments, context);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017-2020 Microsoft Corporation and others.
* Copyright (c) 2017-2021 Microsoft Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand All @@ -17,7 +17,6 @@
import java.io.InputStreamReader;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.HashMap;
Expand Down Expand Up @@ -120,11 +119,7 @@ public String[] getFullyQualifiedName(String uri, int[] lines, int[] columns) th
String filePath = AdapterUtils.toPath(uri);
// For file uri, read the file contents directly and pass them to the ast parser.
if (filePath != null && Files.isRegularFile(Paths.get(filePath))) {
Charset cs = (Charset) this.options.get(Constants.DEBUGGEE_ENCODING);
if (cs == null) {
cs = Charset.defaultCharset();
}
String source = readFile(filePath, cs);
String source = readFile(filePath);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When parsing Java source files, let's keep using the same encoding as JDT language server.

parser.setSource(source.toCharArray());
/**
* See the java doc for { @link ASTParser#setResolveBindings(boolean) }.
Expand Down Expand Up @@ -293,10 +288,10 @@ private static IClassFile resolveClassFile(String uriString) {
return null;
}

private static String readFile(String filePath, Charset cs) {
private static String readFile(String filePath) {
StringBuilder builder = new StringBuilder();
try (BufferedReader bufferReader =
new BufferedReader(new InputStreamReader(new FileInputStream(filePath), cs))) {
new BufferedReader(new InputStreamReader(new FileInputStream(filePath)))) {
final int BUFFER_SIZE = 4096;
char[] buffer = new char[BUFFER_SIZE];
while (true) {
Expand Down