Avoid NPE when replacement property does not exist
See gh-15394
This commit is contained in:
parent
6906859a60
commit
a1b71ef910
@ -137,6 +137,9 @@ class PropertiesMigrationReporter {
|
|||||||
if (lastDot != -1) {
|
if (lastDot != -1) {
|
||||||
ConfigurationMetadataProperty property = this.allProperties
|
ConfigurationMetadataProperty property = this.allProperties
|
||||||
.get(fullId.substring(0, lastDot));
|
.get(fullId.substring(0, lastDot));
|
||||||
|
if (property == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
String type = property.getType();
|
String type = property.getType();
|
||||||
if (type != null && type.startsWith(Map.class.getName())) {
|
if (type != null && type.startsWith(Map.class.getName())) {
|
||||||
int lastComma = type.lastIndexOf(',');
|
int lastComma = type.lastIndexOf(',');
|
||||||
|
@ -152,6 +152,19 @@ public class PropertiesMigrationReporterTests {
|
|||||||
+ "'test.inconvertible' uses an incompatible target type");
|
+ "'test.inconvertible' uses an incompatible target type");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void invalidReplacementHandled() throws IOException {
|
||||||
|
this.environment.getPropertySources().addFirst(loadPropertySource("first",
|
||||||
|
"config/config-error-invalid-replacement.properties"));
|
||||||
|
String report = createErrorReport(
|
||||||
|
loadRepository("metadata/sample-metadata-invalid-replacement.json"));
|
||||||
|
assertThat(report).isNotNull();
|
||||||
|
assertThat(report).containsSubsequence("Property source 'first'",
|
||||||
|
"deprecated.six.test", "Line: 1", "Reason",
|
||||||
|
"Replacement key 'does.not.exist' uses an incompatible target type");
|
||||||
|
assertThat(report).doesNotContain("null");
|
||||||
|
}
|
||||||
|
|
||||||
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 @@
|
|||||||
|
deprecated.six.test=abc
|
@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"properties": [
|
||||||
|
{
|
||||||
|
"name": "deprecated.six.test",
|
||||||
|
"type": "java.lang.String",
|
||||||
|
"deprecation": {
|
||||||
|
"replacement": "does.not.exist",
|
||||||
|
"level": "error"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user