Skip to content

Commit c355868

Browse files
committed
Merge branch '3.1.x'
Closes gh-37063
2 parents 06d8ad0 + 6780b80 commit c355868

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ private void reportConfigurationErrorsIfNecessary(LoggerContext loggerContext) {
275275

276276
private void configureByResourceUrl(LoggingInitializationContext initializationContext, LoggerContext loggerContext,
277277
URL url) throws JoranException {
278-
if (url.toString().endsWith(".xml")) {
278+
if (url.getPath().endsWith(".xml")) {
279279
JoranConfigurator configurator = new SpringBootJoranConfigurator(initializationContext);
280280
configurator.setContext(loggerContext);
281281
configurator.doConfigure(url);

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/logback/LogbackLoggingSystemTests.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,25 @@ void whenConfigurationErrorIsDetectedUnderlyingCausesAreIncludedAsSuppressedExce
782782
.hasAtLeastOneElementOfType(DynamicClassLoadingException.class));
783783
}
784784

785+
@Test
786+
void whenConfigLocationIsNotXmlThenIllegalArgumentExceptionShouldBeThrown() {
787+
this.loggingSystem.beforeInitialize();
788+
assertThatIllegalStateException()
789+
.isThrownBy(() -> initialize(this.initializationContext, "classpath:logback-invalid-format.txt",
790+
getLogFile(tmpDir() + "/tmp.log", null)))
791+
.satisfies((ex) -> assertThat(ex.getCause()).isInstanceOf(IllegalArgumentException.class)
792+
.hasMessageStartingWith("Unsupported file extension"));
793+
}
794+
795+
@Test
796+
void whenConfigLocationIsXmlAndHasQueryParametersThenIllegalArgumentExceptionShouldNotBeThrown() {
797+
this.loggingSystem.beforeInitialize();
798+
assertThatIllegalStateException()
799+
.isThrownBy(() -> initialize(this.initializationContext, "file:///logback-nonexistent.xml?raw=true",
800+
getLogFile(tmpDir() + "/tmp.log", null)))
801+
.satisfies((ex) -> assertThat(ex.getCause()).isNotInstanceOf(IllegalArgumentException.class));
802+
}
803+
785804
private void initialize(LoggingInitializationContext context, String configLocation, LogFile logFile) {
786805
this.loggingSystem.getSystemProperties((ConfigurableEnvironment) context.getEnvironment()).apply(logFile);
787806
this.loggingSystem.beforeInitialize();

spring-boot-project/spring-boot/src/test/resources/logback-invalid-format.txt

Whitespace-only changes.

0 commit comments

Comments
 (0)