Skip to content

Commit 7143f91

Browse files
committed
Merge tag 'rel/2.25.1' into 2.x-site-pro
Release `2.25.1`
2 parents 7c9a7ed + bda6336 commit 7143f91

File tree

40 files changed

+1188
-195
lines changed

40 files changed

+1188
-195
lines changed

.github/dependabot.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ updates:
9090
registries:
9191
- maven-central
9292
ignore:
93+
# `com.github.spotbugs:spotbugs-annotations:4.9.0` and onwards require Java 11
94+
- dependency-name: "com.github.spotbugs:spotbugs-annotations"
95+
versions: [ "[4.9.0,)" ]
9396
# Jetty 10.x does not have an internal logging API
9497
- dependency-name: "org.eclipse.jetty:*"
9598
versions: [ "[10,)" ]

log4j-api/src/main/resources/META-INF/native-image/org.apache.logging.log4j/log4j-api/resource-config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
}
77
]
88
}
9-
}
9+
}

log4j-core-test/src/test/java/org/apache/logging/log4j/core/LoggerContextTest.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,26 @@
1717
package org.apache.logging.log4j.core;
1818

1919
import static org.assertj.core.api.Assertions.assertThat;
20+
import static org.mockito.Mockito.CALLS_REAL_METHODS;
2021
import static org.mockito.Mockito.mock;
22+
import static org.mockito.Mockito.withSettings;
2123

2224
import java.util.Collection;
2325
import java.util.concurrent.ExecutorService;
2426
import java.util.concurrent.Executors;
2527
import java.util.concurrent.Future;
2628
import java.util.stream.Collectors;
2729
import java.util.stream.IntStream;
30+
import org.apache.logging.log4j.core.config.AbstractConfiguration;
31+
import org.apache.logging.log4j.core.config.Configuration;
32+
import org.apache.logging.log4j.core.config.ConfigurationSource;
33+
import org.apache.logging.log4j.core.config.DefaultConfiguration;
2834
import org.apache.logging.log4j.message.MessageFactory;
2935
import org.apache.logging.log4j.message.MessageFactory2;
3036
import org.junit.jupiter.api.Assertions;
3137
import org.junit.jupiter.api.Test;
3238
import org.junit.jupiter.api.TestInfo;
39+
import org.junitpioneer.jupiter.Issue;
3340

3441
class LoggerContextTest {
3542

@@ -75,4 +82,23 @@ void getLoggers_can_be_updated_concurrently(final TestInfo testInfo) {
7582
executorService.shutdown();
7683
}
7784
}
85+
86+
@Test
87+
@Issue("https://github.com/apache/logging-log4j2/issues/3770")
88+
void start_should_fallback_on_reconfigure_if_context_already_started(final TestInfo testInfo) {
89+
final String testName = testInfo.getDisplayName();
90+
try (final LoggerContext loggerContext = new LoggerContext(testName)) {
91+
loggerContext.start();
92+
assertThat(loggerContext.isStarted()).isTrue();
93+
assertThat(loggerContext.getConfiguration()).isInstanceOf(DefaultConfiguration.class);
94+
// Start
95+
Configuration configuration = mock(
96+
AbstractConfiguration.class,
97+
withSettings()
98+
.useConstructor(null, ConfigurationSource.NULL_SOURCE)
99+
.defaultAnswer(CALLS_REAL_METHODS));
100+
loggerContext.start(configuration);
101+
assertThat(loggerContext.getConfiguration()).isSameAs(configuration);
102+
}
103+
}
78104
}

log4j-core-test/src/test/java/org/apache/logging/log4j/core/ShutdownDisabledTest.java

Lines changed: 68 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,84 @@
1616
*/
1717
package org.apache.logging.log4j.core;
1818

19-
import static org.junit.jupiter.api.Assertions.assertFalse;
20-
import static org.junit.jupiter.api.Assertions.assertNull;
19+
import static org.apache.logging.log4j.core.util.ReflectionUtil.getFieldValue;
20+
import static org.assertj.core.api.Assertions.assertThat;
21+
import static org.mockito.Mockito.CALLS_REAL_METHODS;
22+
import static org.mockito.Mockito.mock;
23+
import static org.mockito.Mockito.when;
24+
import static org.mockito.Mockito.withSettings;
2125

2226
import java.lang.reflect.Field;
27+
import org.apache.logging.log4j.core.config.AbstractConfiguration;
2328
import org.apache.logging.log4j.core.config.Configuration;
29+
import org.apache.logging.log4j.core.config.ConfigurationSource;
2430
import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
25-
import org.apache.logging.log4j.core.util.ReflectionUtil;
2631
import org.apache.logging.log4j.test.junit.SetTestProperty;
2732
import org.junit.jupiter.api.Test;
33+
import org.junit.jupiter.api.TestInfo;
2834

2935
@SetTestProperty(key = "log4j2.isWebapp", value = "false")
30-
@LoggerContextSource("log4j-test3.xml")
3136
class ShutdownDisabledTest {
3237

38+
private static final Field shutdownCallbackField;
39+
40+
static {
41+
try {
42+
shutdownCallbackField = LoggerContext.class.getDeclaredField("shutdownCallback");
43+
} catch (NoSuchFieldException e) {
44+
throw new RuntimeException(e);
45+
}
46+
}
47+
48+
@Test
49+
@LoggerContextSource("log4j-test3.xml")
50+
void testShutdownFlag(final Configuration config, final LoggerContext ctx) {
51+
assertThat(config.isShutdownHookEnabled())
52+
.as("Shutdown hook is enabled")
53+
.isFalse();
54+
assertThat(getFieldValue(shutdownCallbackField, ctx))
55+
.as("Shutdown callback")
56+
.isNull();
57+
}
58+
3359
@Test
34-
void testShutdownFlag(final Configuration config, final LoggerContext ctx) throws NoSuchFieldException {
35-
Field shutdownCallback = LoggerContext.class.getDeclaredField("shutdownCallback");
36-
Object fieldValue = ReflectionUtil.getFieldValue(shutdownCallback, ctx);
37-
assertFalse(config.isShutdownHookEnabled(), "Shutdown hook is enabled");
38-
assertNull(fieldValue, "Shutdown callback");
60+
void whenLoggerContextInitialized_respectsShutdownDisabled(TestInfo testInfo) {
61+
Configuration configuration = mockConfiguration();
62+
when(configuration.isShutdownHookEnabled()).thenReturn(false);
63+
try (final LoggerContext ctx = new LoggerContext(testInfo.getDisplayName())) {
64+
ctx.start(configuration);
65+
assertThat(ctx.isStarted()).isTrue();
66+
assertThat(ctx.getConfiguration()).isSameAs(configuration);
67+
assertThat(getFieldValue(shutdownCallbackField, ctx))
68+
.as("Shutdown callback")
69+
.isNull();
70+
}
71+
}
72+
73+
@Test
74+
void whenLoggerContextStarted_ignoresShutdownDisabled(TestInfo testInfo) {
75+
// Traditional behavior: during reconfiguration, the shutdown hook is not removed.
76+
Configuration initialConfiguration = mockConfiguration();
77+
when(initialConfiguration.isShutdownHookEnabled()).thenReturn(true);
78+
Configuration configuration = mockConfiguration();
79+
when(configuration.isShutdownHookEnabled()).thenReturn(false);
80+
try (final LoggerContext ctx = new LoggerContext(testInfo.getDisplayName())) {
81+
ctx.start(initialConfiguration);
82+
assertThat(ctx.isStarted()).isTrue();
83+
Object shutdownCallback = getFieldValue(shutdownCallbackField, ctx);
84+
assertThat(shutdownCallback).as("Shutdown callback").isNotNull();
85+
ctx.start(configuration);
86+
assertThat(getFieldValue(shutdownCallbackField, ctx))
87+
.as("Shutdown callback")
88+
.isSameAs(shutdownCallback);
89+
}
90+
}
91+
92+
private static Configuration mockConfiguration() {
93+
return mock(
94+
AbstractConfiguration.class,
95+
withSettings()
96+
.useConstructor(null, ConfigurationSource.NULL_SOURCE)
97+
.defaultAnswer(CALLS_REAL_METHODS));
3998
}
4099
}

0 commit comments

Comments
 (0)