Merge branch '2.7.x'

Closes gh-33250
pull/33251/head
Andy Wilkinson 2 years ago
commit 931cc8a508

@ -99,8 +99,10 @@ class PropertiesMigrationReporter {
List<ConfigurationMetadataProperty> candidates = this.allProperties.values().stream().filter(filter) List<ConfigurationMetadataProperty> candidates = this.allProperties.values().stream().filter(filter)
.collect(Collectors.toList()); .collect(Collectors.toList());
getPropertySourcesAsMap().forEach((name, source) -> candidates.forEach((metadata) -> { getPropertySourcesAsMap().forEach((name, source) -> candidates.forEach((metadata) -> {
ConfigurationProperty configurationProperty = source ConfigurationPropertyName metadataName = ConfigurationPropertyName.isValid(metadata.getId())
.getConfigurationProperty(ConfigurationPropertyName.of(metadata.getId())); ? ConfigurationPropertyName.of(metadata.getId())
: ConfigurationPropertyName.adapt(metadata.getId(), '.');
ConfigurationProperty configurationProperty = source.getConfigurationProperty(metadataName);
if (configurationProperty != null) { if (configurationProperty != null) {
result.add(name, result.add(name,
new PropertyMigration(configurationProperty, metadata, determineReplacementMetadata(metadata))); new PropertyMigration(configurationProperty, metadata, determineReplacementMetadata(metadata)));

@ -18,6 +18,7 @@ package org.springframework.boot.context.properties.migrator;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -144,6 +145,15 @@ class PropertiesMigrationReporterTests {
assertThat(report).doesNotContain("null"); assertThat(report).doesNotContain("null");
} }
@Test
void invalidNameHandledGracefully() {
this.environment.getPropertySources()
.addFirst(new MapPropertySource("first", Collections.singletonMap("invalid.property-name", "value")));
String report = createWarningReport(loadRepository("metadata/sample-metadata-invalid-name.json"));
assertThat(report).isNotNull();
assertThat(report).contains("Key: invalid.PropertyName").contains("Replacement: valid.property-name");
}
private List<String> mapToNames(PropertySources sources) { private List<String> mapToNames(PropertySources sources) {
List<String> names = new ArrayList<>(); List<String> names = new ArrayList<>();
for (PropertySource<?> source : sources) { for (PropertySource<?> source : sources) {

@ -0,0 +1,16 @@
{
"properties": [
{
"name": "invalid.PropertyName",
"type": "java.lang.String",
"deprecation": {
"replacement": "valid.property-name",
"level": "error"
}
},
{
"name": "valid.property-name",
"type": "java.lang.String"
}
]
}
Loading…
Cancel
Save