Skip to content

Commit 28dad44

Browse files
committed
Be defensive about JUL calls from JAR Handler
Update nested JAR support to only obtain JUL loggers when absolutely necessary and to defensively deal with failures. Prior to this commit it was not possible to override `java.util.logging.manager` to use a nested JAR as the logger implementation. Fixes gh-9848
1 parent b9cfe21 commit 28dad44

File tree

1 file changed

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

1 file changed

+15
-5
lines changed

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

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2016 the original author or authors.
2+
* Copyright 2012-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -71,8 +71,6 @@ public class Handler extends URLStreamHandler {
7171
rootFileCache = new SoftReference<Map<File, JarFile>>(null);
7272
}
7373

74-
private final Logger logger = Logger.getLogger(getClass().getName());
75-
7674
private final JarFile jarFile;
7775

7876
private URLStreamHandler fallbackHandler;
@@ -105,17 +103,29 @@ private URLConnection openFallbackConnection(URL url, Exception reason)
105103
}
106104
catch (Exception ex) {
107105
if (reason instanceof IOException) {
108-
this.logger.log(Level.FINEST, "Unable to open fallback handler", ex);
106+
log(false, "Unable to open fallback handler", ex);
109107
throw (IOException) reason;
110108
}
111-
this.logger.log(Level.WARNING, "Unable to open fallback handler", ex);
109+
log(true, "Unable to open fallback handler", ex);
112110
if (reason instanceof RuntimeException) {
113111
throw (RuntimeException) reason;
114112
}
115113
throw new IllegalStateException(reason);
116114
}
117115
}
118116

117+
private void log(boolean warning, String message, Exception cause) {
118+
try {
119+
Logger.getLogger(getClass().getName())
120+
.log((warning ? Level.WARNING : Level.FINEST), message, cause);
121+
}
122+
catch (Exception ex) {
123+
if (warning) {
124+
System.err.println("WARNING: " + message);
125+
}
126+
}
127+
}
128+
119129
private URLStreamHandler getFallbackHandler() {
120130
if (this.fallbackHandler != null) {
121131
return this.fallbackHandler;

0 commit comments

Comments
 (0)