Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

c.m.h.config.HumptyBootstrap not coping with paths on Windows. #6

Open
dtbullock opened this issue Jul 9, 2015 · 2 comments
Open

Comments

@dtbullock
Copy link

On Windows,

  Thread.currentThread().getContextClassLoader().getResources(assetsDir)

produces a collection of URL's with a file:/ scheme, which, when one invokes #toFile() on them, yield a string of the form:

"/C:/foo/bar"

Unfortunately, Paths.get("/C:/foo/bar") throws an exception:

java.nio.file.InvalidPathException: Illegal char <:> at index 2: /C:/foo/bar
    at sun.nio.fs.WindowsPathParser.normalize(WindowsPathParser.java:182)
    at sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:153)
    at sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:77)
    at sun.nio.fs.WindowsPath.parse(WindowsPath.java:94)
    at sun.nio.fs.WindowsFileSystem.getPath(WindowsFileSystem.java:255)
    at java.nio.file.Paths.get(Paths.java:84)
    at co.mewf.humpty.config.HumptyBootstrap.getDefaultLocator(HumptyBootstrap.java:184)
    at co.mewf.humpty.config.HumptyBootstrap$$Lambda$22/321299532.get(Unknown Source)
    at java.util.Optional.orElseGet(Optional.java:267)
    at co.mewf.humpty.config.HumptyBootstrap.<init>(HumptyBootstrap.java:80)
    at co.mewf.humpty.servlet.HumptyServletContextInitializer.onStartup(HumptyServletContextInitializer.java:29)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5156)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    ... 43 more

Not sure if this is a JVM 'bug' or not, but I do note that the Javadoc for java.nio.files.Paths.get(String,String...) says:

Note that while this method is very convenient, using it will imply an assumed reference to the default FileSystem and limit the utility of the calling code. Hence it should not be used in library code intended for flexible reuse.

An alternative which happens to work is:

Paths.get(url.toURI())

... because it retains the 'file:' scheme, that seems to be better. This does seem to be the 'right' way to de-reference URLs to local file paths.

dtbullock pushed a commit to dtbullock/humpty that referenced this issue Jul 9, 2015
dtbullock pushed a commit to dtbullock/humpty that referenced this issue Jul 9, 2015
dtbullock pushed a commit to dtbullock/humpty that referenced this issue Jul 9, 2015
@mwanji
Copy link
Owner

mwanji commented Jul 16, 2015

Thanks for identifying the issue and for the PR. I'm sorry for not having gotten to this yet. I will get to it soon, however as I don't have a Windows computer, I'll have to ask you to verify that it works before releasing it.

@dtbullock
Copy link
Author

Hi, I can of course run the tests on a Windows computer for you. Just let me know which branch/tag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants