Fix "Allow optional directories without sub-directories"

Fix the update to `resolvePatternEmptyDirectories` introduced in
commit 01dd68e29e which was incorrectly checking `isOptional`.

See gh-26677
pull/26691/head
izeye 4 years ago committed by Phillip Webb
parent 01dd68e29e
commit 38b9a833bd

@ -267,7 +267,7 @@ public class StandardConfigDataLocationResolver
private Set<StandardConfigDataResource> resolvePatternEmptyDirectories(StandardConfigDataReference reference) {
Resource[] subdirectories = this.resourceLoader.getResources(reference.getDirectory(), ResourceType.DIRECTORY);
ConfigDataLocation location = reference.getConfigDataLocation();
if (location.isOptional() && ObjectUtils.isEmpty(subdirectories)) {
if (!location.isOptional() && ObjectUtils.isEmpty(subdirectories)) {
String message = String.format("Config data location '%s' contains no subdirectories", location);
throw new ConfigDataLocationNotFoundException(location, message, null);
}

@ -715,7 +715,8 @@ class ConfigDataEnvironmentPostProcessorIntegrationTests {
void runWhenMandatoryWildcardLocationHasNoSubdirectories() {
assertThatExceptionOfType(ConfigDataLocationNotFoundException.class).isThrownBy(
() -> this.application.run("--spring.config.location=file:src/test/resources/config/0-empty/*/"))
.withMessage("Config data location 'file:src/test/resources/config/0-empty/*/' cannot be found");
.withMessage(
"Config data location 'file:src/test/resources/config/0-empty/*/' contains no subdirectories");
}
@Test

Loading…
Cancel
Save