Skip to content

Commit 8d491f2

Browse files
committed
Create FilePermission lazily in JarURLConnection
JarURLConnection is very performance sensitive. The change in 3772d9f meant that every JarURLConnection would create a FilePermission, irrespective of whether it was actually used. This commit updates JarURLConnection to create its FilePermission lazily. When there is no security manager a permission will no longer be created at all. Closes gh-5411 See gh-6215
1 parent 1754662 commit 8d491f2

File tree

1 file changed

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

1 file changed

+5
-3
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ protected URLConnection openConnection(URL u) throws IOException {
7070

7171
private final JarFile jarFile;
7272

73-
private final Permission permission;
73+
private Permission permission;
7474

7575
private JarEntryData jarEntryData;
7676

@@ -91,8 +91,6 @@ protected JarURLConnection(URL url, JarFile jarFile) throws IOException {
9191
}
9292
this.jarFile = jarFile;
9393
this.jarEntryName = getJarEntryName(spec);
94-
this.permission = new FilePermission(jarFile.getRootJarFile().getFile().getPath(),
95-
READ_ACTION);
9694
}
9795

9896
private String getNormalizedFile(URL url) {
@@ -225,6 +223,10 @@ public String getContentType() {
225223

226224
@Override
227225
public Permission getPermission() throws IOException {
226+
if (this.permission == null) {
227+
this.permission = new FilePermission(
228+
this.jarFile.getRootJarFile().getFile().getPath(), READ_ACTION);
229+
}
228230
return this.permission;
229231
}
230232

0 commit comments

Comments
 (0)