Jetty version(s)
12.0.17
Jetty Environment
ee10
Java version/vendor (use: java -version)
openjdk version "17.0.14" 2025-01-21
OpenJDK Runtime Environment Temurin-17.0.14+7 (build 17.0.14+7)
OpenJDK 64-Bit Server VM Temurin-17.0.14+7 (build 17.0.14+7, mixed mode, sharing)
OS type/version
Ubuntu 20.04.6 LTS
Description
Resources located inside the JAR files are wrongfully identified as aliased resources.
The URI we get inside PathResource class looks like this:
jar:file:/home/oleg.smirnov/Projects/private/jetty.project/jetty-core/jetty-util/src/test/resources/jar-file-resource.jar!/rez/deep/zzz
And the toUri method is called inside resolveAlias method, the resulting URI will look like this:
jar:file:///home/oleg.smirnov/Projects/private/jetty.project/jetty-core/jetty-util/src/test/resources/jar-file-resource.jar!/rez/deep/zzz.
As a result, isAlias returns true because the original URI and URI from the path are not the same. It looks like URIUtil.correctURI should be invoked on the uri parameter passed into PathResource constructor.
How to reproduce?
A small test to reproduce the problem. I executed it from org.eclipse.jetty.util.resource.MountedPathResourceTest class inside jetty-util module
@Test
public void testClassLoaderResourceIsNotAnAlias() throws MalformedURLException {
Path testZip = MavenPaths.findTestResourceFile("jar-file-resource.jar");
URI uri = testZip.toUri();
ClassLoader loader = new URLClassLoader(new URL[] {uri.toURL()});
ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
try (ResourceFactory.Closeable resourceFactory = ResourceFactory.closeable())
{
Thread.currentThread().setContextClassLoader(loader);
Resource r = resourceFactory.newClassLoaderResource("rez/deep/zzz", false);
assertThat("file inside a JAR should NOT be an alias", r.isAlias(), is(false));
} finally {
Thread.currentThread().setContextClassLoader(oldLoader);
}
}
Please let me know if you need any additional information
Jetty version(s)
12.0.17
Jetty Environment
ee10
Java version/vendor
(use: java -version)openjdk version "17.0.14" 2025-01-21
OpenJDK Runtime Environment Temurin-17.0.14+7 (build 17.0.14+7)
OpenJDK 64-Bit Server VM Temurin-17.0.14+7 (build 17.0.14+7, mixed mode, sharing)
OS type/version
Ubuntu 20.04.6 LTS
Description
Resources located inside the JAR files are wrongfully identified as aliased resources.
The URI we get inside
PathResourceclass looks like this:jar:file:/home/oleg.smirnov/Projects/private/jetty.project/jetty-core/jetty-util/src/test/resources/jar-file-resource.jar!/rez/deep/zzzAnd the
toUrimethod is called insideresolveAliasmethod, the resulting URI will look like this:jar:file:///home/oleg.smirnov/Projects/private/jetty.project/jetty-core/jetty-util/src/test/resources/jar-file-resource.jar!/rez/deep/zzz.As a result,
isAliasreturns true because the original URI and URI from the path are not the same. It looks likeURIUtil.correctURIshould be invoked on theuriparameter passed intoPathResourceconstructor.How to reproduce?
A small test to reproduce the problem. I executed it from
org.eclipse.jetty.util.resource.MountedPathResourceTestclass insidejetty-utilmodulePlease let me know if you need any additional information