Skip to content

Spring Boot 3.2.2 new nested jar mechanism does not resolve resources containing space in the path #39655

@slovi

Description

@slovi

Hi,
after we migrated from Spring Boot 3.1.8 to 3.2.2, our applications installed in path containing empty space suddenly stoped working.

The problem seems to be in new "nested jar" mechanism used to resource locating in the jar/war file.

I tried to prepare simple test which fails in 3.2.2:

    @BeforeAll
    static void setUpClass() {
        Handlers.register();
    }

    @Test
    void testNestedJarPathWithSpaceEncoded() throws Exception {

        var nestedJarUrl = new URL("jar:nested:/C:/Program%20Files/app.jar/!BOOT-INF/classes/!/static/app/nested.jar");
        var nestedJarConnection = nestedJarUrl.openConnection();
        assertThat(nestedJarConnection.getLastModified(), greaterThan(0L));
    }

This works fine in 3.1.8:

    @BeforeAll
    static void setUpClass() {
        JarFile.registerUrlProtocolHandler();
    }

    @Test
    void testNestedJarPathWithSpaceEncoded() throws Exception {

        var jarUrl = new URL("jar:file:/C:/Program%20Files/app.jar/!/BOOT-INF/classes/!/static/app/nested.jar");
        var jarConnection = jarUrl.openConnection();
        assertThat(jarConnection.getLastModified(), greaterThan(0L));
    }

I think that the problem is in implementation of the NestedUrlConnection class:

	private NestedLocation parseNestedLocation(URL url) throws MalformedURLException {
		try {
			return NestedLocation.parse(url.getPath());
		}
		catch (IllegalArgumentException ex) {
			throw new MalformedURLException(ex.getMessage());
		}
	}

Path should be decoded before passing it to NestedLocation.parse method. The URL passed to static method NestedLocation.fromUrl is also decoded before passed to NestedLocation.parse method.

So I would propose this change:

        private NestedLocation parseNestedLocation(URL url) throws MalformedURLException {
		try {
			return NestedLocation.parse(UrlDecoder.decode(url.getPath()));
		}
		catch (IllegalArgumentException ex) {
			throw new MalformedURLException(ex.getMessage());
		}
	}

Will create PR for that If you do not mind.

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: supersededAn issue that has been superseded by another

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions