From 8d491f278bc321c4ec9473f368c0135a65bf1bf1 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Fri, 24 Jun 2016 11:49:35 +0100 Subject: [PATCH] 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 --- .../springframework/boot/loader/jar/JarURLConnection.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarURLConnection.java b/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarURLConnection.java index 720808c123..d8ad9905e6 100644 --- a/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarURLConnection.java +++ b/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarURLConnection.java @@ -70,7 +70,7 @@ class JarURLConnection extends java.net.JarURLConnection { private final JarFile jarFile; - private final Permission permission; + private Permission permission; private JarEntryData jarEntryData; @@ -91,8 +91,6 @@ class JarURLConnection extends java.net.JarURLConnection { } this.jarFile = jarFile; this.jarEntryName = getJarEntryName(spec); - this.permission = new FilePermission(jarFile.getRootJarFile().getFile().getPath(), - READ_ACTION); } private String getNormalizedFile(URL url) { @@ -225,6 +223,10 @@ class JarURLConnection extends java.net.JarURLConnection { @Override public Permission getPermission() throws IOException { + if (this.permission == null) { + this.permission = new FilePermission( + this.jarFile.getRootJarFile().getFile().getPath(), READ_ACTION); + } return this.permission; }