diff --git a/cfg4j-core/src/main/java/org/cfg4j/source/context/propertiesprovider/YamlBasedPropertiesProvider.java b/cfg4j-core/src/main/java/org/cfg4j/source/context/propertiesprovider/YamlBasedPropertiesProvider.java index ed370bc..6b7364c 100644 --- a/cfg4j-core/src/main/java/org/cfg4j/source/context/propertiesprovider/YamlBasedPropertiesProvider.java +++ b/cfg4j-core/src/main/java/org/cfg4j/source/context/propertiesprovider/YamlBasedPropertiesProvider.java @@ -53,8 +53,10 @@ public Properties getProperties(InputStream inputStream) { Object object = yaml.load(reader); - Map yamlAsMap = convertToMap(object); - properties.putAll(flatten(yamlAsMap)); + if (object != null) { + Map yamlAsMap = convertToMap(object); + properties.putAll(flatten(yamlAsMap)); + } return properties; diff --git a/cfg4j-core/src/test/java/org/cfg4j/source/context/propertiesprovider/YamlBasedPropertiesProviderTest.java b/cfg4j-core/src/test/java/org/cfg4j/source/context/propertiesprovider/YamlBasedPropertiesProviderTest.java index 85ff08a..b5f4371 100644 --- a/cfg4j-core/src/test/java/org/cfg4j/source/context/propertiesprovider/YamlBasedPropertiesProviderTest.java +++ b/cfg4j-core/src/test/java/org/cfg4j/source/context/propertiesprovider/YamlBasedPropertiesProviderTest.java @@ -101,6 +101,15 @@ public void shouldThrowForNonYamlFile() throws Exception { expectedException.expect(IllegalStateException.class); provider.getProperties(input); } + } + + @Test + public void shouldSupportEmptyDocument() throws Exception { + String path = "org/cfg4j/source/propertiesprovider/YamlBasedPropertiesProviderTest_shouldSupportEmptyDocument.yaml"; + + try (InputStream input = getClass().getClassLoader().getResourceAsStream(path)) { + assertThat(provider.getProperties(input)).isEmpty(); + } } } \ No newline at end of file diff --git a/cfg4j-core/src/test/resources/org/cfg4j/source/propertiesprovider/YamlBasedPropertiesProviderTest_shouldSupportEmptyDocument.yaml b/cfg4j-core/src/test/resources/org/cfg4j/source/propertiesprovider/YamlBasedPropertiesProviderTest_shouldSupportEmptyDocument.yaml new file mode 100644 index 0000000..e69de29