From afb4c9d3b286fe5d57bbce3fa06e4199031be116 Mon Sep 17 00:00:00 2001 From: hengyunabc Date: Thu, 14 Mar 2019 20:39:38 +0800 Subject: [PATCH] polish "support windows unicode file path" #574 --- .../main/java/com/taobao/arthas/boot/Bootstrap.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java b/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java index fff39bd3a..60eb01af4 100644 --- a/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java +++ b/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java @@ -6,7 +6,6 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.net.URL; import java.net.URLClassLoader; -import java.net.URLDecoder; import java.security.CodeSource; import java.util.ArrayList; import java.util.Arrays; @@ -339,13 +338,12 @@ public class Bootstrap { if (arthasHomeDir == null) { CodeSource codeSource = Bootstrap.class.getProtectionDomain().getCodeSource(); if (codeSource != null) { - String bootJarPath = codeSource.getLocation().getFile(); try { - //convert unicode path to normal path - bootJarPath = URLDecoder.decode(bootJarPath, "utf-8"); - verifyArthasHome(new File(bootJarPath).getParent()); - arthasHomeDir = new File(bootJarPath).getParentFile(); - } catch (Exception e) { + // https://stackoverflow.com/a/17870390 + File bootJarPath = new File(codeSource.getLocation().toURI().getSchemeSpecificPart()); + verifyArthasHome(bootJarPath.getParent()); + arthasHomeDir = bootJarPath.getParentFile(); + } catch (Throwable e) { // ignore }