From 0354c98fad273996c065017c6d8c81bc13fc2be7 Mon Sep 17 00:00:00 2001 From: Guillaume Smet Date: Sat, 16 Mar 2024 17:27:34 +0100 Subject: [PATCH] Avoid building a URI again and again in JarResource --- .../io/quarkus/bootstrap/runner/JarResource.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/independent-projects/bootstrap/runner/src/main/java/io/quarkus/bootstrap/runner/JarResource.java b/independent-projects/bootstrap/runner/src/main/java/io/quarkus/bootstrap/runner/JarResource.java index 8b4da096a891d..0689be2dea647 100644 --- a/independent-projects/bootstrap/runner/src/main/java/io/quarkus/bootstrap/runner/JarResource.java +++ b/independent-projects/bootstrap/runner/src/main/java/io/quarkus/bootstrap/runner/JarResource.java @@ -29,6 +29,7 @@ public class JarResource implements ClassLoadingResource { private final ManifestInfo manifestInfo; private final Path jarPath; + private final URI jarUri; private final Lock readLock; private final Lock writeLock; @@ -46,6 +47,7 @@ public class JarResource implements ClassLoadingResource { public JarResource(ManifestInfo manifestInfo, Path jarPath) { this.manifestInfo = manifestInfo; this.jarPath = jarPath; + this.jarUri = jarPath.toUri(); final ReadWriteLock readWriteLock = new ReentrantReadWriteLock(); this.readLock = readWriteLock.readLock(); this.writeLock = readWriteLock.writeLock(); @@ -55,13 +57,8 @@ public JarResource(ManifestInfo manifestInfo, Path jarPath) { public void init() { final URL url; try { - String path = jarPath.toAbsolutePath().toString(); - if (!path.startsWith("/")) { - path = '/' + path; - } - URI uri = new URI("file", null, path, null); - url = uri.toURL(); - } catch (URISyntaxException | MalformedURLException e) { + url = this.jarUri.toURL(); + } catch (MalformedURLException e) { throw new RuntimeException("Unable to create protection domain for " + jarPath, e); } this.protectionDomain = new ProtectionDomain(new CodeSource(url, (Certificate[]) null), null); @@ -110,7 +107,6 @@ public URL getResourceURL(String resource) { if (realName.endsWith("/")) { realName = realName.substring(0, realName.length() - 1); } - final URI jarUri = jarPath.toUri(); // first create a URI which includes both the jar file path and the relative resource name // and then invoke a toURL on it. The URI reconstruction allows for any encoding to be done // for the "path" which includes the "realName"