diff --git a/spring-boot/src/main/java/org/springframework/boot/StartupInfoLogger.java b/spring-boot/src/main/java/org/springframework/boot/StartupInfoLogger.java index 01057bd6f7a..85f1253a526 100644 --- a/spring-boot/src/main/java/org/springframework/boot/StartupInfoLogger.java +++ b/spring-boot/src/main/java/org/springframework/boot/StartupInfoLogger.java @@ -17,11 +17,13 @@ package org.springframework.boot; import java.io.File; +import java.io.IOException; import java.lang.management.ManagementFactory; import java.net.InetAddress; import java.net.JarURLConnection; import java.net.URL; import java.net.URLConnection; +import java.security.CodeSource; import java.security.ProtectionDomain; import java.util.concurrent.Callable; @@ -162,15 +164,13 @@ class StartupInfoLogger { try { ProtectionDomain protectionDomain = (this.sourceClass == null ? getClass() : this.sourceClass).getProtectionDomain(); + CodeSource codeSource = protectionDomain.getCodeSource(); + if (codeSource == null) { + return null; + } URL location = protectionDomain.getCodeSource().getLocation(); - File file; URLConnection connection = location.openConnection(); - if (connection instanceof JarURLConnection) { - file = new File(((JarURLConnection) connection).getJarFile().getName()); - } - else { - file = new File(location.getPath()); - } + File file = getFile(location, connection); if (file.exists()) { return file; } @@ -180,6 +180,13 @@ class StartupInfoLogger { return null; } + private File getFile(URL location, URLConnection connection) throws IOException { + if (connection instanceof JarURLConnection) { + return new File(((JarURLConnection) connection).getJarFile().getName()); + } + return new File(location.getPath()); + } + private String getValue(String prefix, Callable call) { return getValue(prefix, call, ""); }