Skip to content

Commit d4b11c8

Browse files
committed
Attempt to fix test failures on Java 9+
See gh-14453
1 parent cef635d commit d4b11c8

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/logger/DevToolsLogFactory.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import java.util.LinkedHashMap;
2020
import java.util.Map;
2121

22+
import org.apache.commons.logging.Log;
23+
2224
import org.springframework.boot.context.event.ApplicationPreparedEvent;
2325
import org.springframework.boot.logging.DeferredLog;
2426
import org.springframework.context.ApplicationListener;
@@ -32,21 +34,21 @@
3234
*/
3335
public final class DevToolsLogFactory {
3436

35-
private static final Map<DeferredLog, Class<?>> logs = new LinkedHashMap<>();
37+
private static final Map<Log, Class<?>> logs = new LinkedHashMap<>();
3638

3739
private DevToolsLogFactory() {
3840
}
3941

4042
/**
41-
* Get a {@link DeferredLog} instance for the specified source that will be
42-
* automatically {@link DeferredLog#switchTo(Class) switched} then the
43-
* {@link AbstractPageRequest context is prepared}.
43+
* Get a {@link Log} instance for the specified source that will be automatically
44+
* {@link DeferredLog#switchTo(Class) switched} then the {@link AbstractPageRequest
45+
* context is prepared}.
4446
* @param source the source for logging
4547
* @return a {@link DeferredLog} instance
4648
*/
47-
public static DeferredLog getLog(Class<?> source) {
49+
public static Log getLog(Class<?> source) {
4850
synchronized (logs) {
49-
DeferredLog log = new DeferredLog();
51+
Log log = new DeferredLog();
5052
logs.put(log, source);
5153
return log;
5254
}
@@ -60,7 +62,11 @@ static class Listener implements ApplicationListener<ApplicationPreparedEvent> {
6062
@Override
6163
public void onApplicationEvent(ApplicationPreparedEvent event) {
6264
synchronized (logs) {
63-
logs.forEach((log, source) -> log.switchTo(source));
65+
logs.forEach((log, source) -> {
66+
if (log instanceof DeferredLog) {
67+
((DeferredLog) log).switchTo(source);
68+
}
69+
});
6470
logs.clear();
6571
}
6672
}

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/DeferredLog.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,7 @@ public void replayTo(Log destination) {
192192
* @param source the source logger
193193
* @param destination the destination logger class
194194
* @return the destination
195-
* @deprecated since 2.1.0 in favor of {@link #switchTo(Class)}
196195
*/
197-
@Deprecated
198196
public static Log replay(Log source, Class<?> destination) {
199197
return replay(source, LogFactory.getLog(destination));
200198
}
@@ -204,9 +202,7 @@ public static Log replay(Log source, Class<?> destination) {
204202
* @param source the source logger
205203
* @param destination the destination logger
206204
* @return the destination
207-
* @deprecated since 2.1.0 in favor of {@link #switchTo(Log)}
208205
*/
209-
@Deprecated
210206
public static Log replay(Log source, Log destination) {
211207
if (source instanceof DeferredLog) {
212208
((DeferredLog) source).replayTo(destination);

0 commit comments

Comments
 (0)