Remove workaround for LOG4J2-3618

Closes gh-41906
This commit is contained in:
Andy Wilkinson
2024-09-11 11:21:32 +01:00
parent 080e43ee36
commit 74f3f8188c

View File

@@ -24,7 +24,6 @@ import java.util.EnumSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.logging.Handler;
import java.util.logging.Level;
@@ -43,7 +42,6 @@ import org.apache.logging.log4j.core.config.plugins.util.PluginRegistry;
import org.apache.logging.log4j.core.util.ShutdownCallbackRegistry;
import org.apache.logging.log4j.jul.Log4jBridgeHandler;
import org.apache.logging.log4j.util.PropertiesUtil;
import org.apache.logging.log4j.util.PropertySource;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -64,7 +62,6 @@ import org.springframework.boot.testsupport.system.CapturedOutput;
import org.springframework.boot.testsupport.system.OutputCaptureExtension;
import org.springframework.core.env.Environment;
import org.springframework.mock.env.MockEnvironment;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.util.ClassUtils;
import org.springframework.util.StringUtils;
@@ -110,7 +107,6 @@ class Log4J2LoggingSystemTests extends AbstractLoggingSystemTests {
this.configuration = loggerContext.getConfiguration();
this.loggingSystem.cleanUp();
this.logger = LogManager.getLogger(getClass());
cleanUpPropertySources();
}
@AfterEach
@@ -119,19 +115,9 @@ class Log4J2LoggingSystemTests extends AbstractLoggingSystemTests {
LoggerContext loggerContext = (LoggerContext) LogManager.getContext(false);
loggerContext.stop();
loggerContext.start(((Reconfigurable) this.configuration).reconfigure());
cleanUpPropertySources();
PluginRegistry.getInstance().clear();
}
@SuppressWarnings("unchecked")
private void cleanUpPropertySources() { // https://issues.apache.org/jira/browse/LOG4J2-3618
PropertiesUtil properties = PropertiesUtil.getProperties();
Object environment = ReflectionTestUtils.getField(properties, "environment");
Set<PropertySource> sources = (Set<PropertySource>) ReflectionTestUtils.getField(environment, "sources");
sources.removeIf((candidate) -> candidate instanceof SpringEnvironmentPropertySource
|| candidate instanceof SpringBootPropertySource);
}
@Test
void noFile(CapturedOutput output) {
this.loggingSystem.beforeInitialize();