From 4637745a6f4d1156b26a3e4ac52c8c42e6662346 Mon Sep 17 00:00:00 2001 From: Jinbo Wang Date: Wed, 18 Oct 2017 18:41:06 +0800 Subject: [PATCH 1/3] fix the inconsistent uri issue for set breakpoint request Signed-off-by: Jinbo Wang --- .../java/debug/core/adapter/AdapterUtils.java | 16 ++++++++++++++++ .../handler/SetBreakpointsRequestHandler.java | 3 ++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/AdapterUtils.java b/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/AdapterUtils.java index 339b0d17b..18fea9679 100644 --- a/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/AdapterUtils.java +++ b/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/AdapterUtils.java @@ -11,8 +11,10 @@ package com.microsoft.java.debug.core.adapter; +import java.io.UnsupportedEncodingException; import java.net.URI; import java.net.URISyntaxException; +import java.net.URLDecoder; import java.nio.charset.StandardCharsets; import java.nio.file.FileSystemNotFoundException; import java.nio.file.Files; @@ -220,4 +222,18 @@ public static String getSHA256HexDigest(String content) { } return buf.toString(); } + + /** + * decode the uri string. + * @param uri + * the uri string + * @return the decoded uri + */ + public static String decodeURIComponent(String uri) { + try { + return URLDecoder.decode(uri, "UTF-8"); + } catch (UnsupportedEncodingException e) { + return uri; + } + } } diff --git a/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/SetBreakpointsRequestHandler.java b/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/SetBreakpointsRequestHandler.java index facd4ad5a..d7a3f5940 100644 --- a/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/SetBreakpointsRequestHandler.java +++ b/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/SetBreakpointsRequestHandler.java @@ -81,7 +81,8 @@ public void handle(Command command, Arguments arguments, Response response, IDeb try { List res = new ArrayList<>(); IBreakpoint[] toAdds = this.convertClientBreakpointsToDebugger(sourcePath, bpArguments.breakpoints, context); - IBreakpoint[] added = manager.setBreakpoints(sourcePath, toAdds, bpArguments.sourceModified); + // The source uri sometimes is encoded by VSCode, the debugger will decode it to keep the uri consistent. + IBreakpoint[] added = manager.setBreakpoints(AdapterUtils.decodeURIComponent(sourcePath), toAdds, bpArguments.sourceModified); for (int i = 0; i < bpArguments.breakpoints.length; i++) { // For newly added breakpoint, should install it to debuggee first. if (toAdds[i] == added[i] && added[i].className() != null) { From 28b7ed6691b080a5cc4756f51d95fdeb75a3c46c Mon Sep 17 00:00:00 2001 From: Jinbo Wang Date: Wed, 18 Oct 2017 18:44:35 +0800 Subject: [PATCH 2/3] add vscode bug number Signed-off-by: Jinbo Wang --- .../debug/core/adapter/handler/SetBreakpointsRequestHandler.java | 1 + 1 file changed, 1 insertion(+) diff --git a/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/SetBreakpointsRequestHandler.java b/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/SetBreakpointsRequestHandler.java index d7a3f5940..bf7194954 100644 --- a/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/SetBreakpointsRequestHandler.java +++ b/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/SetBreakpointsRequestHandler.java @@ -81,6 +81,7 @@ public void handle(Command command, Arguments arguments, Response response, IDeb try { List res = new ArrayList<>(); IBreakpoint[] toAdds = this.convertClientBreakpointsToDebugger(sourcePath, bpArguments.breakpoints, context); + // See the VSCode bug https://github.com/Microsoft/vscode/issues/36471. // The source uri sometimes is encoded by VSCode, the debugger will decode it to keep the uri consistent. IBreakpoint[] added = manager.setBreakpoints(AdapterUtils.decodeURIComponent(sourcePath), toAdds, bpArguments.sourceModified); for (int i = 0; i < bpArguments.breakpoints.length; i++) { From be5dcf23a1482dae891f3ee32816872f88104f31 Mon Sep 17 00:00:00 2001 From: Jinbo Wang Date: Wed, 18 Oct 2017 19:23:17 +0800 Subject: [PATCH 3/3] fix review comments Signed-off-by: Jinbo Wang --- .../com/microsoft/java/debug/core/adapter/AdapterUtils.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/AdapterUtils.java b/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/AdapterUtils.java index 18fea9679..96cec919d 100644 --- a/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/AdapterUtils.java +++ b/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/AdapterUtils.java @@ -224,14 +224,14 @@ public static String getSHA256HexDigest(String content) { } /** - * decode the uri string. + * Decode the uri string. * @param uri * the uri string * @return the decoded uri */ public static String decodeURIComponent(String uri) { try { - return URLDecoder.decode(uri, "UTF-8"); + return URLDecoder.decode(uri, StandardCharsets.UTF_8.name()); } catch (UnsupportedEncodingException e) { return uri; }