From 45a24b87051243f80775e283d1e127b80cdb7d02 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Mon, 25 Sep 2017 09:45:56 +0100 Subject: [PATCH] Upgrade to Log4j 2.9.1 This commit uppgrade our Log4j dependency to 2.9.1. It also modifies ModifiedClassPathRunner so that log4j-*.jar jars are always excluded from the class path when using the runner. This is necessary due to a change in Log4j [1] which makes assumptions about the class loader hierarchy that do not hold true when using the modified class path runner. Specifically, it assumes that the system class loader should always be used to load providers. This is exactly what we don't want to happen when using the modified class path runner as it breaks the filtering of the class path and leads to Log4j classes being loaded from both the system class loader and the filtering class loader. Closes gh-10407 [1] https://github.com/apache/logging-log4j2/commit/9422ca7489d545b92dda9dd357c1b057d7a2f217 --- spring-boot-dependencies/pom.xml | 2 +- .../runner/classpath/ModifiedClassPathRunner.java | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/spring-boot-dependencies/pom.xml b/spring-boot-dependencies/pom.xml index e796efa455..48f93eb6c3 100644 --- a/spring-boot-dependencies/pom.xml +++ b/spring-boot-dependencies/pom.xml @@ -131,7 +131,7 @@ 1.0.0 5.0.0.RC2 3.5.3 - 2.9.0 + 2.9.1 1.2.3 1.16.18 2.1.1 diff --git a/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/runner/classpath/ModifiedClassPathRunner.java b/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/runner/classpath/ModifiedClassPathRunner.java index 51dd37cea0..fa182099c6 100644 --- a/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/runner/classpath/ModifiedClassPathRunner.java +++ b/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/runner/classpath/ModifiedClassPathRunner.java @@ -216,10 +216,13 @@ public class ModifiedClassPathRunner extends BlockJUnit4ClassRunner { private final AntPathMatcher matcher = new AntPathMatcher(); private ClassPathEntryFilter(Class testClass) throws Exception { + this.exclusions = new ArrayList<>(); + this.exclusions.add("log4j-*.jar"); ClassPathExclusions exclusions = AnnotationUtils.findAnnotation(testClass, ClassPathExclusions.class); - this.exclusions = exclusions == null ? Collections.emptyList() - : Arrays.asList(exclusions.value()); + if (exclusions != null) { + this.exclusions.addAll(Arrays.asList(exclusions.value())); + } } private boolean isExcluded(URL url) throws Exception {