Skip to content

Commit 1451f30

Browse files
committed
Polish PropertySourceProcessor
1 parent 4b54ca4 commit 1451f30

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

spring-core/src/main/java/org/springframework/core/io/support/PropertySourceProcessor.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,22 +49,24 @@
4949
*/
5050
public class PropertySourceProcessor {
5151

52-
private static final PropertySourceFactory DEFAULT_PROPERTY_SOURCE_FACTORY = new DefaultPropertySourceFactory();
52+
private static final PropertySourceFactory defaultPropertySourceFactory = new DefaultPropertySourceFactory();
5353

5454
private static final Log logger = LogFactory.getLog(PropertySourceProcessor.class);
5555

56+
5657
private final ConfigurableEnvironment environment;
5758

5859
private final ResourceLoader resourceLoader;
5960

60-
private final List<String> propertySourceNames;
61+
private final List<String> propertySourceNames = new ArrayList<>();
62+
6163

6264
public PropertySourceProcessor(ConfigurableEnvironment environment, ResourceLoader resourceLoader) {
6365
this.environment = environment;
6466
this.resourceLoader = resourceLoader;
65-
this.propertySourceNames = new ArrayList<>();
6667
}
6768

69+
6870
/**
6971
* Process the specified {@link PropertySourceDescriptor} against the
7072
* environment managed by this instance.
@@ -78,7 +80,7 @@ public void processPropertySource(PropertySourceDescriptor descriptor) throws IO
7880
Assert.isTrue(locations.size() > 0, "At least one @PropertySource(value) location is required");
7981
boolean ignoreResourceNotFound = descriptor.ignoreResourceNotFound();
8082
PropertySourceFactory factory = (descriptor.propertySourceFactory() != null ?
81-
instantiateClass(descriptor.propertySourceFactory()) : DEFAULT_PROPERTY_SOURCE_FACTORY);
83+
instantiateClass(descriptor.propertySourceFactory()) : defaultPropertySourceFactory);
8284

8385
for (String location : locations) {
8486
try {
@@ -100,13 +102,13 @@ public void processPropertySource(PropertySourceDescriptor descriptor) throws IO
100102
}
101103
}
102104

103-
private void addPropertySource(org.springframework.core.env.PropertySource<?> propertySource) {
105+
private void addPropertySource(PropertySource<?> propertySource) {
104106
String name = propertySource.getName();
105107
MutablePropertySources propertySources = this.environment.getPropertySources();
106108

107109
if (this.propertySourceNames.contains(name)) {
108110
// We've already added a version, we need to extend it
109-
org.springframework.core.env.PropertySource<?> existing = propertySources.get(name);
111+
PropertySource<?> existing = propertySources.get(name);
110112
if (existing != null) {
111113
PropertySource<?> newSource = (propertySource instanceof ResourcePropertySource rps ?
112114
rps.withResourceName() : propertySource);
@@ -136,7 +138,8 @@ private void addPropertySource(org.springframework.core.env.PropertySource<?> pr
136138
this.propertySourceNames.add(name);
137139
}
138140

139-
private PropertySourceFactory instantiateClass(Class<? extends PropertySourceFactory> type) {
141+
142+
private static PropertySourceFactory instantiateClass(Class<? extends PropertySourceFactory> type) {
140143
try {
141144
Constructor<? extends PropertySourceFactory> constructor = type.getDeclaredConstructor();
142145
ReflectionUtils.makeAccessible(constructor);

0 commit comments

Comments
 (0)