-
- Notifications
You must be signed in to change notification settings - Fork 157
Closed
Description
When running the script goal under windows I get following exception:
java.lang.reflect.InvocationTargetException at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:119) at java.base/java.lang.reflect.Method.invoke(Method.java:565) at scala_maven_executions.MainHelper.runMain(MainHelper.java:156) at scala_maven_executions.MainWithArgsInFile.main(MainWithArgsInFile.java:30) Caused by: java.nio.file.InvalidPathException: Illegal char <:> at index 3: /C:/Users/ ... /.scalaScriptGen/ at java.base/sun.nio.fs.WindowsPathParser.normalize(WindowsPathParser.java:191) at java.base/sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:142) at java.base/sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:46) at java.base/sun.nio.fs.WindowsPath.parse(WindowsPath.java:92) at java.base/sun.nio.fs.WindowsFileSystem.getPath(WindowsFileSystem.java:203) at java.base/java.nio.file.Path.of(Path.java:148) at java.base/java.nio.file.Paths.get(Paths.java:69) at dotty.tools.dotc.core.MacroClassLoader$.$anonfun$1(MacroClassLoader.scala:25) The problem is in method appendUrlToClasspathCollection of scala_maven_executions.MainHelper which uses getFile() of URL to covert the URL back to file path. That doesn't work under windows, as the resulting file starts with forward slash, e.g. /C:/Users/ ... /.scalaScriptGen/. The correct way to convert the URL back to file is first to convert the URL to URI, then create a File out of that and finally to use the absolute path of the file:
private static void appendUrlToClasspathCollection(ClassLoader cl, Collection<String> classpath) { if (cl == null) { cl = Thread.currentThread().getContextClassLoader(); } while (cl != null) { if (cl instanceof URLClassLoader) { URLClassLoader ucl = (URLClassLoader) cl; URL[] urls = ucl.getURLs(); for (URL url : urls) { try { classpath.add(new File(url.toURI()).getAbsolutePath()); // Fix here } catch (URISyntaxException e) { throw new RuntimeException("Unable to convert URL to file: " + url, e); } } } cl = cl.getParent(); } }Metadata
Metadata
Assignees
Labels
No labels