Menu

#294 WrapperJarApp: building File URL

v3.5.23
open
nobody
None
5
2016-12-21
2016-12-21
No

WrapperJarApp.java class builds file URL using the following line: new URL( "file:" + file.getAbsolutePath() ); which leads to issues under windows.

The correct way to build such an URL is: file.toURI().toURL();

This issue was raised by a uber JAR build using Spring Boot 1.3.8.RELEASE. During the launch of that application, the parent ClassLoader's URLs are retrieved and resolved using new File(url.toURI()) which leads to a java.lang.IllegalArgumentException: URI is not hierarchical.

For example, the following snippet:
File f = new File("c:/temp");
System.out.println(new URL( "file:" + f.getAbsolutePath() ));
System.out.println(f.toURI().toURL());

will output:
file:c:/temp
file:/c:/temp/

Notice the / after the colon of the second line.

Trying to instantiate a File from the first URL leads to an error and the second works.

Discussion


Log in to post a comment.

MongoDB Logo MongoDB