Skip to content
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

Avoid building a URI again and again in JarResource #39508

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand All @@ -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);
Expand Down Expand Up @@ -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"
Expand Down
Loading