Skip to content

Commit a67c8e4

Browse files
committed
Perform analysis even when property is not in the environment
Closes gh-33261
1 parent 6c1962f commit a67c8e4

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/diagnostics/analyzer/InvalidConfigurationPropertyValueFailureAnalyzer.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -51,7 +51,7 @@ class InvalidConfigurationPropertyValueFailureAnalyzer
5151
protected FailureAnalysis analyze(Throwable rootFailure, InvalidConfigurationPropertyValueException cause) {
5252
List<Descriptor> descriptors = getDescriptors(cause.getName());
5353
if (descriptors.isEmpty()) {
54-
return null;
54+
descriptors = List.of(new Descriptor(null, cause.getValue(), null));
5555
}
5656
StringBuilder description = new StringBuilder();
5757
appendDetails(description, cause, descriptors);

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/InvalidConfigurationPropertyValueFailureAnalyzerTests.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -45,7 +45,8 @@ void analysisWithNullEnvironment() {
4545
InvalidConfigurationPropertyValueException failure = new InvalidConfigurationPropertyValueException(
4646
"test.property", "invalid", "This is not valid.");
4747
FailureAnalysis analysis = new InvalidConfigurationPropertyValueFailureAnalyzer(null).analyze(failure);
48-
assertThat(analysis).isNull();
48+
assertThat(analysis.getDescription())
49+
.contains("Invalid value 'invalid' for configuration property 'test.property'.");
4950
}
5051

5152
@Test
@@ -98,7 +99,9 @@ void analysisWithKnownPropertyAndOtherCandidates() {
9899
void analysisWithUnknownKey() {
99100
InvalidConfigurationPropertyValueException failure = new InvalidConfigurationPropertyValueException(
100101
"test.key.not.defined", "invalid", "This is not valid.");
101-
assertThat(performAnalysis(failure)).isNull();
102+
FailureAnalysis analysis = performAnalysis(failure);
103+
assertThat(analysis.getDescription())
104+
.contains("Invalid value 'invalid' for configuration property 'test.key.not.defined'.");
102105
}
103106

104107
private void assertCommonParts(InvalidConfigurationPropertyValueException failure, FailureAnalysis analysis) {

0 commit comments

Comments
 (0)