From d4b11c8fa63e5b409b970d0a1addf796dc390e42 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 12 Sep 2018 18:31:50 -0700 Subject: [PATCH] Attempt to fix test failures on Java 9+ See gh-14453 --- .../devtools/logger/DevToolsLogFactory.java | 20 ++++++++++++------- .../boot/logging/DeferredLog.java | 4 ---- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/logger/DevToolsLogFactory.java b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/logger/DevToolsLogFactory.java index 387160aaf1..9454570ac7 100644 --- a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/logger/DevToolsLogFactory.java +++ b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/logger/DevToolsLogFactory.java @@ -19,6 +19,8 @@ package org.springframework.boot.devtools.logger; import java.util.LinkedHashMap; import java.util.Map; +import org.apache.commons.logging.Log; + import org.springframework.boot.context.event.ApplicationPreparedEvent; import org.springframework.boot.logging.DeferredLog; import org.springframework.context.ApplicationListener; @@ -32,21 +34,21 @@ import org.springframework.data.domain.AbstractPageRequest; */ public final class DevToolsLogFactory { - private static final Map> logs = new LinkedHashMap<>(); + private static final Map> logs = new LinkedHashMap<>(); private DevToolsLogFactory() { } /** - * Get a {@link DeferredLog} instance for the specified source that will be - * automatically {@link DeferredLog#switchTo(Class) switched} then the - * {@link AbstractPageRequest context is prepared}. + * Get a {@link Log} instance for the specified source that will be automatically + * {@link DeferredLog#switchTo(Class) switched} then the {@link AbstractPageRequest + * context is prepared}. * @param source the source for logging * @return a {@link DeferredLog} instance */ - public static DeferredLog getLog(Class source) { + public static Log getLog(Class source) { synchronized (logs) { - DeferredLog log = new DeferredLog(); + Log log = new DeferredLog(); logs.put(log, source); return log; } @@ -60,7 +62,11 @@ public final class DevToolsLogFactory { @Override public void onApplicationEvent(ApplicationPreparedEvent event) { synchronized (logs) { - logs.forEach((log, source) -> log.switchTo(source)); + logs.forEach((log, source) -> { + if (log instanceof DeferredLog) { + ((DeferredLog) log).switchTo(source); + } + }); logs.clear(); } } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/DeferredLog.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/DeferredLog.java index 578b8ee4d1..2d86075b71 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/DeferredLog.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/DeferredLog.java @@ -192,9 +192,7 @@ public class DeferredLog implements Log { * @param source the source logger * @param destination the destination logger class * @return the destination - * @deprecated since 2.1.0 in favor of {@link #switchTo(Class)} */ - @Deprecated public static Log replay(Log source, Class destination) { return replay(source, LogFactory.getLog(destination)); } @@ -204,9 +202,7 @@ public class DeferredLog implements Log { * @param source the source logger * @param destination the destination logger * @return the destination - * @deprecated since 2.1.0 in favor of {@link #switchTo(Log)} */ - @Deprecated public static Log replay(Log source, Log destination) { if (source instanceof DeferredLog) { ((DeferredLog) source).replayTo(destination);