Skip to content

Commit 35b26b5

Browse files
author
Phillip Webb
committed
Add caching to JarFile.getUrl()
Fixes spring-projectsgh-1178
1 parent 200cd53 commit 35b26b5

File tree

1 file changed

+8
-3
lines changed
  • spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar

1 file changed

+8
-3
lines changed

spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarFile.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ public class JarFile extends java.util.jar.JarFile implements Iterable<JarEntryD
8484

8585
private SoftReference<Manifest> manifest;
8686

87+
private URL url;
88+
8789
/**
8890
* Create a new {@link JarFile} backed by the specified file.
8991
* @param file the root jar file
@@ -417,9 +419,12 @@ public void close() throws IOException {
417419
* @throws MalformedURLException
418420
*/
419421
public URL getUrl() throws MalformedURLException {
420-
Handler handler = new Handler(this);
421-
String file = this.rootFile.getFile().toURI() + this.pathFromRoot + "!/";
422-
return new URL("jar", "", -1, file, handler);
422+
if (this.url == null) {
423+
Handler handler = new Handler(this);
424+
String file = this.rootFile.getFile().toURI() + this.pathFromRoot + "!/";
425+
this.url = new URL("jar", "", -1, file, handler);
426+
}
427+
return this.url;
423428
}
424429

425430
@Override

0 commit comments

Comments
 (0)