Skip to content

jar URLs created using a context URL with our Handler point to the root of the jar rather than an entry #7021

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

Closed
wilkinsona opened this issue Sep 26, 2016 · 5 comments
Assignees
Labels
type: bug A general bug
Milestone

Comments

@wilkinsona
Copy link
Member

wilkinsona commented Sep 26, 2016

When added to JarURLConnectionTests, this test will fail:

@Test
public void connectionToEntryInNestedJarFromUrlThatUsesExistingUrlAsContext()
        throws Exception {
    URL url = new URL(new URL("jar", null, -1,
            "file:" + getAbsolutePath() + "!/nested.jar!/", new Handler()), "/3.dat");
    JarFile nested = this.jarFile
            .getNestedJarFile(this.jarFile.getEntry("nested.jar"));
    assertThat(JarURLConnection.get(url, nested).getInputStream())
            .hasSameContentAs(new ByteArrayInputStream(new byte[] { 3 }));
}

Note that the Handler is a org.springframework.boot.loader.jar.Handler. If it is a sun.net.www.protocol.jar.Handler then the test passes. The key difference is what's returned from getFile() of the URL.

Handler getFile()
Ours /import.sql
JDK's file:/Users/awilkinson/dev/spring/spring-boot/1.4.x/spring-boot-tools/spring-boot-loader/target/junit8413793381285871673/junit3981300331907567187.tmp!/nested.jar!/import.sql

This difference throws out the spec-related logic in JarURLConnection. The lack of a !/ leaves the JarURLConnection with an empty jarEntryName, i.e. pointing to the root of the nested jar. As a result, the attempt to get the input stream fails:

java.io.IOException: no entry name specified
    at org.springframework.boot.loader.jar.JarURLConnection.getInputStream(JarURLConnection.java:164)
    at org.springframework.boot.loader.jar.JarURLConnectionTests.connectionToEntryInNestedFromUrlThatUsesExistingUrlAsContext(JarURLConnectionTests.java:136)
    …
@wilkinsona wilkinsona added the type: bug A general bug label Sep 26, 2016
@wilkinsona wilkinsona added this to the 1.4.2 milestone Sep 26, 2016
wilkinsona added a commit to wilkinsona/spring-boot that referenced this issue Sep 26, 2016
Previously our handler didn't override parseURL or sameFile which
resulted in behaviour that differed from that of the JDK's handler.
Crucially, this would result in our JarURLConnection being passed
a spec that didn't contain a "!/". A knock-on effect of this was
that the connection would point to the root of the jar rather than
the intended entry.

Closes spring-projectsgh-7021
@wilkinsona
Copy link
Member Author

Possible fix: https://github.com/wilkinsona/spring-boot/tree/gh-7021

@philwebb Could you please cast an eye over this one as well?

@snicoll
Copy link
Member

snicoll commented Oct 24, 2016

@philwebb could you please put that review higher on your stack? If we manage to resolve this, #6983 is probably going to be a non-issue and we'll be able to remove the code we've added in 1.4.1 to workaround the fact that classpath: doesn't work with fat jars. Thanks!

@philwebb philwebb removed the for: team-attention An issue we'd like other members of the team to review label Oct 26, 2016
@philwebb
Copy link
Member

I think this is good, although it's pretty hard to be 100% confident. I've merged it.

@wilkinsona
Copy link
Member Author

And… it broke stuff

@wilkinsona wilkinsona reopened this Oct 26, 2016
@wilkinsona wilkinsona assigned wilkinsona and unassigned philwebb Oct 26, 2016
@philwebb
Copy link
Member

This was without doubt one of my most useless reviews ever. I knew I'd probably messed it up, but panicked because the issue had been open so long and committed it anyway. To make matters worse I did git commit --amend, you couldn't tell what had changed and it looked you were the author.

Sorry about that :(

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

No branches or pull requests

3 participants