diff --git a/spring-boot-project/spring-boot-properties-migrator/src/main/java/org/springframework/boot/context/properties/migrator/PropertiesMigrationReporter.java b/spring-boot-project/spring-boot-properties-migrator/src/main/java/org/springframework/boot/context/properties/migrator/PropertiesMigrationReporter.java index 4c90120c42..dc4b7017d1 100644 --- a/spring-boot-project/spring-boot-properties-migrator/src/main/java/org/springframework/boot/context/properties/migrator/PropertiesMigrationReporter.java +++ b/spring-boot-project/spring-boot-properties-migrator/src/main/java/org/springframework/boot/context/properties/migrator/PropertiesMigrationReporter.java @@ -137,6 +137,9 @@ class PropertiesMigrationReporter { if (lastDot != -1) { ConfigurationMetadataProperty property = this.allProperties .get(fullId.substring(0, lastDot)); + if (property == null) { + return null; + } String type = property.getType(); if (type != null && type.startsWith(Map.class.getName())) { int lastComma = type.lastIndexOf(','); diff --git a/spring-boot-project/spring-boot-properties-migrator/src/test/java/org/springframework/boot/context/properties/migrator/PropertiesMigrationReporterTests.java b/spring-boot-project/spring-boot-properties-migrator/src/test/java/org/springframework/boot/context/properties/migrator/PropertiesMigrationReporterTests.java index f57fd750c1..076f01af31 100644 --- a/spring-boot-project/spring-boot-properties-migrator/src/test/java/org/springframework/boot/context/properties/migrator/PropertiesMigrationReporterTests.java +++ b/spring-boot-project/spring-boot-properties-migrator/src/test/java/org/springframework/boot/context/properties/migrator/PropertiesMigrationReporterTests.java @@ -152,6 +152,19 @@ public class PropertiesMigrationReporterTests { + "'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 mapToNames(PropertySources sources) { List names = new ArrayList<>(); for (PropertySource source : sources) { diff --git a/spring-boot-project/spring-boot-properties-migrator/src/test/resources/config/config-error-invalid-replacement.properties b/spring-boot-project/spring-boot-properties-migrator/src/test/resources/config/config-error-invalid-replacement.properties new file mode 100644 index 0000000000..4584cd05e0 --- /dev/null +++ b/spring-boot-project/spring-boot-properties-migrator/src/test/resources/config/config-error-invalid-replacement.properties @@ -0,0 +1 @@ +deprecated.six.test=abc diff --git a/spring-boot-project/spring-boot-properties-migrator/src/test/resources/metadata/sample-metadata-invalid-replacement.json b/spring-boot-project/spring-boot-properties-migrator/src/test/resources/metadata/sample-metadata-invalid-replacement.json new file mode 100644 index 0000000000..0794d85820 --- /dev/null +++ b/spring-boot-project/spring-boot-properties-migrator/src/test/resources/metadata/sample-metadata-invalid-replacement.json @@ -0,0 +1,12 @@ +{ + "properties": [ + { + "name": "deprecated.six.test", + "type": "java.lang.String", + "deprecation": { + "replacement": "does.not.exist", + "level": "error" + } + } + ] +} \ No newline at end of file