Skip to content

Commit 11ec9f9

Browse files
committed
Merge branch '3.1.x'
Closes spring-projectsgh-37571
2 parents 845c4dd + 02f71d8 commit 11ec9f9

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

.idea/inspectionProfiles/Project_Default.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/StandardConfigDataLocationResolver.java

+3
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,9 @@ private Set<StandardConfigDataReference> getReferencesForFile(ConfigDataLocation
228228
return Collections.singleton(reference);
229229
}
230230
}
231+
if (configDataLocation.isOptional()) {
232+
return Collections.emptySet();
233+
}
231234
throw new IllegalStateException("File extension is not known to any PropertySourceLoader. "
232235
+ "If the location is meant to reference a directory, it must end in '/' or File.separator");
233236
}

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/StandardConfigDataLocationResolverTests.java

+21
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
*
4444
* @author Madhura Bhave
4545
* @author Phillip Webb
46+
* @author Moritz Halbritter
4647
*/
4748
class StandardConfigDataLocationResolverTests {
4849

@@ -263,6 +264,26 @@ void resolveProfileSpecificWhenLocationIsFileReturnsEmptyList() {
263264
assertThat(locations).isEmpty();
264265
}
265266

267+
@Test
268+
void resolveWhenOptionalAndLoaderIsUnknownShouldNotFail() {
269+
ConfigDataLocation location = ConfigDataLocation.of("optional:some-unknown-loader:dummy.properties");
270+
assertThatNoException().isThrownBy(() -> this.resolver.resolve(this.context, location));
271+
}
272+
273+
@Test
274+
void resolveWhenOptionalAndLoaderIsUnknownAndExtensionIsUnknownShouldNotFail() {
275+
ConfigDataLocation location = ConfigDataLocation
276+
.of("optional:some-unknown-loader:dummy.some-unknown-extension");
277+
List<StandardConfigDataResource> locations = this.resolver.resolve(this.context, location);
278+
assertThatNoException().isThrownBy(() -> this.resolver.resolve(this.context, location));
279+
}
280+
281+
@Test
282+
void resolveWhenOptionalAndExtensionIsUnknownShouldNotFail() {
283+
ConfigDataLocation location = ConfigDataLocation.of("optional:file:dummy.some-unknown-extension");
284+
assertThatNoException().isThrownBy(() -> this.resolver.resolve(this.context, location));
285+
}
286+
266287
private String filePath(String... components) {
267288
return "file [" + String.join(File.separator, components) + "]";
268289
}

0 commit comments

Comments
 (0)