Skip to content

Commit 7e8ffc7

Browse files
committed
CompositePropertySource rejects getPropertyNames call when containing a non-enumerable source
Issue: SPR-12788
1 parent f786fc3 commit 7e8ffc7

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

spring-core/src/main/java/org/springframework/core/env/CompositePropertySource.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -78,9 +78,11 @@ public boolean containsProperty(String name) {
7878
public String[] getPropertyNames() {
7979
Set<String> names = new LinkedHashSet<String>();
8080
for (PropertySource<?> propertySource : this.propertySources) {
81-
if (propertySource instanceof EnumerablePropertySource) {
82-
names.addAll(Arrays.asList(((EnumerablePropertySource<?>) propertySource).getPropertyNames()));
81+
if (!(propertySource instanceof EnumerablePropertySource)) {
82+
throw new IllegalStateException(
83+
"Failed to enumerate property names due to non-enumerable property source: " + propertySource);
8384
}
85+
names.addAll(Arrays.asList(((EnumerablePropertySource<?>) propertySource).getPropertyNames()));
8486
}
8587
return StringUtils.toStringArray(names);
8688
}

0 commit comments

Comments
 (0)