So, well, apart from the fact that the constructor you want to invoke uses a URL
object as first parameter instead of a String
, I guess the behavior you see may have something to do with the fact that file
scheme URI are hierarchical, but if you don't provide any hierarchy symbol (i.e. the slash) the constructor gives priority to the spec part (i.e. the second parameter) over the context part (i.e. the first parameter).
For example, when you forget the trailing slash on file:/foo/bar
, what you really are indicating is file bar
in directory foo
. If you pass along a relative path such as images/a.png
, the constructor combines the two as best as it can: of course it cannot append a relative path to what it believes to be a file, giving as a result file:/foo/bar/images/a.png
, so it just replaces the bar
file with the file you passed as second parameter, giving as a result file:/foo/images/a.png
.
The same applies to your second example: file:foo.bar
indicates a foo.bar
file, but when you pass the second parameter representing an images.a.png
file, the substitution happens as explained in the preceding example, giving a result of file:images.a.png
. This happens, I believe, because you are missing hierarchy symbols (i.e. slashes) where you need to have them in order to obtain the desired result.
This is really a guess rather than an ol' good informed answer.
However, when you type:
URL url = new URL(new URL("file:foo.bar/"), "images.a.png");
System.out.println(url);
appending a /
suffix to one of the parts, as you say you had, the result indeed changes, contrary to what you affirm, giving the following result:
file:foo.bar/images.a.png
which appears to be consistent with my guesses.
Still, since I never used OneJar, from your question is unclear what your input really is, and what you want to obtain as a result.