#13 JarClassLoader.getResource() returns URL for unloadable resources

Unstable (example)
open
nobody
None
5
2014-09-10
2014-02-19
David Ehrmann
No

Also documented a bit over here.

When there's a file in a jar file bundled by One-JAR, jarClassLoader.getResource("/file") returns a URL, e.g. jar:file://home/dehrmann/bin/glacierpipe.jar!/lib/aws-java-sdk-1.7.1.jar!//awssdk_config_default.json. When called with "file" (no leading forward slash, a URL is also returned, e.g. jar:file://home/dehrmann/bin/glacierpipe.jar!/lib/aws-java-sdk-1.7.1.jar!/awssdk_config_default.json. Only the latter can actually be opened.

Looking into one-jar/src/com/simontuffs/onejar/JarClassLoader.java, I saw $resource get rewritten so the forward slash was trimmed, but it wasn't used when generating the URL.

This change seems to fix things so that both return an openable URL, but I'm not sure if there's a side effect:

1167c1167
<                 return urlFactory.getURL(entry.codebase, resource);
---
>                 return urlFactory.getURL(entry.codebase, $resource);

Discussion