From 77103e7a2b30d4a36055f7dc9f3ae278e24c07e2 Mon Sep 17 00:00:00 2001 From: Axel Howind Date: Thu, 16 Dec 2021 08:43:09 +0100 Subject: [PATCH] fix #4357: spoon doesn't handle paths containinig spaces correctly --- src/main/java/spoon/support/StandardEnvironment.java | 4 +++- .../visitor/java/JavaReflectionTreeBuilderTest.java | 7 +++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/java/spoon/support/StandardEnvironment.java b/src/main/java/spoon/support/StandardEnvironment.java index 30008b2f8e7..ce76b43117d 100644 --- a/src/main/java/spoon/support/StandardEnvironment.java +++ b/src/main/java/spoon/support/StandardEnvironment.java @@ -43,7 +43,9 @@ import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; +import java.net.URLDecoder; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -418,7 +420,7 @@ public void setInputClassLoader(ClassLoader aClassLoader) { if (onlyFileURLs) { List classpath = new ArrayList<>(); for (URL url : urls) { - classpath.add(url.getPath()); + classpath.add(URLDecoder.decode(url.getPath(), StandardCharsets.UTF_8)); } setSourceClasspath(classpath.toArray(new String[0])); } else { diff --git a/src/test/java/spoon/support/visitor/java/JavaReflectionTreeBuilderTest.java b/src/test/java/spoon/support/visitor/java/JavaReflectionTreeBuilderTest.java index 66a1a914765..a34c0d301fb 100644 --- a/src/test/java/spoon/support/visitor/java/JavaReflectionTreeBuilderTest.java +++ b/src/test/java/spoon/support/visitor/java/JavaReflectionTreeBuilderTest.java @@ -28,6 +28,8 @@ import java.lang.annotation.Retention; import java.net.CookieManager; import java.net.URLClassLoader; +import java.net.URLDecoder; +import java.nio.charset.StandardCharsets; import java.time.format.TextStyle; import java.util.ArrayList; import java.util.Arrays; @@ -603,10 +605,11 @@ public void testPartialShadow() { @Test public void testInnerClassWithConstructorParameterAnnotated() { Launcher launcher = new Launcher(); - launcher.addInputResource(JavaReflectionTreeBuilderTest.class + launcher.addInputResource(URLDecoder.decode(JavaReflectionTreeBuilderTest.class .getClassLoader() .getResource("annotated-parameter-on-nested-class-constructor/Caller.java") - .getPath()); + .getPath(), + StandardCharsets.UTF_8)); launcher.getEnvironment().setSourceClasspath( new String[]{ "src/test/resources"