Skip to content

Commit 931cc8a

Browse files
committed
Merge branch '2.7.x'
Closes gh-33250
2 parents be89f03 + 0a3c403 commit 931cc8a

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

spring-boot-project/spring-boot-tools/spring-boot-properties-migrator/src/main/java/org/springframework/boot/context/properties/migrator/PropertiesMigrationReporter.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,10 @@ private Map<String, List<PropertyMigration>> getMatchingProperties(
9999
List<ConfigurationMetadataProperty> candidates = this.allProperties.values().stream().filter(filter)
100100
.collect(Collectors.toList());
101101
getPropertySourcesAsMap().forEach((name, source) -> candidates.forEach((metadata) -> {
102-
ConfigurationProperty configurationProperty = source
103-
.getConfigurationProperty(ConfigurationPropertyName.of(metadata.getId()));
102+
ConfigurationPropertyName metadataName = ConfigurationPropertyName.isValid(metadata.getId())
103+
? ConfigurationPropertyName.of(metadata.getId())
104+
: ConfigurationPropertyName.adapt(metadata.getId(), '.');
105+
ConfigurationProperty configurationProperty = source.getConfigurationProperty(metadataName);
104106
if (configurationProperty != null) {
105107
result.add(name,
106108
new PropertyMigration(configurationProperty, metadata, determineReplacementMetadata(metadata)));

spring-boot-project/spring-boot-tools/spring-boot-properties-migrator/src/test/java/org/springframework/boot/context/properties/migrator/PropertiesMigrationReporterTests.java

+10
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import java.io.IOException;
2020
import java.util.ArrayList;
21+
import java.util.Collections;
2122
import java.util.LinkedHashMap;
2223
import java.util.List;
2324
import java.util.Map;
@@ -144,6 +145,15 @@ void invalidReplacementHandled() throws IOException {
144145
assertThat(report).doesNotContain("null");
145146
}
146147

148+
@Test
149+
void invalidNameHandledGracefully() {
150+
this.environment.getPropertySources()
151+
.addFirst(new MapPropertySource("first", Collections.singletonMap("invalid.property-name", "value")));
152+
String report = createWarningReport(loadRepository("metadata/sample-metadata-invalid-name.json"));
153+
assertThat(report).isNotNull();
154+
assertThat(report).contains("Key: invalid.PropertyName").contains("Replacement: valid.property-name");
155+
}
156+
147157
private List<String> mapToNames(PropertySources sources) {
148158
List<String> names = new ArrayList<>();
149159
for (PropertySource<?> source : sources) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"properties": [
3+
{
4+
"name": "invalid.PropertyName",
5+
"type": "java.lang.String",
6+
"deprecation": {
7+
"replacement": "valid.property-name",
8+
"level": "error"
9+
}
10+
},
11+
{
12+
"name": "valid.property-name",
13+
"type": "java.lang.String"
14+
}
15+
]
16+
}

0 commit comments

Comments
 (0)