Skip to content

Commit a7492fa

Browse files
committed
Polishing
1 parent ecf23ff commit a7492fa

File tree

7 files changed

+48
-36
lines changed

7 files changed

+48
-36
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,12 +671,15 @@ public void preInstantiateSingletons() throws BeansException {
671671
if (this.logger.isDebugEnabled()) {
672672
this.logger.debug("Pre-instantiating singletons in " + this);
673673
}
674+
674675
List<String> beanNames;
675676
synchronized (this.beanDefinitionMap) {
676677
// Iterate over a copy to allow for init methods which in turn register new bean definitions.
677678
// While this may not be part of the regular factory bootstrap, it does otherwise work fine.
678679
beanNames = new ArrayList<String>(this.beanDefinitionNames);
679680
}
681+
682+
// Trigger initialization of all non-lazy singleton beans...
680683
for (String beanName : beanNames) {
681684
RootBeanDefinition bd = getMergedLocalBeanDefinition(beanName);
682685
if (!bd.isAbstract() && bd.isSingleton() && !bd.isLazyInit()) {

spring-beans/src/main/java/org/springframework/beans/factory/support/StaticListableBeanFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2014 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.
@@ -133,7 +133,7 @@ else if (beanNames.length > 1) {
133133
public Object getBean(String name, Object... args) throws BeansException {
134134
if (args != null) {
135135
throw new UnsupportedOperationException(
136-
"StaticListableBeanFactory does not support explicit bean creation arguments)");
136+
"StaticListableBeanFactory does not support explicit bean creation arguments");
137137
}
138138
return getBean(name);
139139
}

spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ public int compare(DeferredImportSelectorHolder o1, DeferredImportSelectorHolder
113113

114114
private final ComponentScanAnnotationParser componentScanParser;
115115

116+
private final ConditionEvaluator conditionEvaluator;
117+
116118
private final Map<ConfigurationClass, ConfigurationClass> configurationClasses =
117119
new LinkedHashMap<ConfigurationClass, ConfigurationClass>();
118120

@@ -125,8 +127,6 @@ public int compare(DeferredImportSelectorHolder o1, DeferredImportSelectorHolder
125127

126128
private final List<DeferredImportSelectorHolder> deferredImportSelectors = new LinkedList<DeferredImportSelectorHolder>();
127129

128-
private final ConditionEvaluator conditionEvaluator;
129-
130130

131131
/**
132132
* Create a new {@link ConfigurationClassParser} instance that will be used
@@ -228,7 +228,7 @@ protected void processConfigurationClass(ConfigurationClass configClass) throws
228228
* multiple times as relevant sources are discovered.
229229
* @param configClass the configuration class being build
230230
* @param sourceClass a source class
231-
* @return the superclass, {@code null} if none found or previously processed
231+
* @return the superclass, or {@code null} if none found or previously processed
232232
*/
233233
protected final SourceClass doProcessConfigurationClass(ConfigurationClass configClass, SourceClass sourceClass) throws IOException {
234234
// recursively process any member (nested) classes first
@@ -675,7 +675,7 @@ public Class<?> loadClass() throws ClassNotFoundException {
675675
if (this.source instanceof Class<?>) {
676676
return (Class<?>) this.source;
677677
}
678-
String className = ((MetadataReader) source).getClassMetadata().getClassName();
678+
String className = ((MetadataReader) this.source).getClassMetadata().getClassName();
679679
return resourceLoader.getClassLoader().loadClass(className);
680680
}
681681

@@ -695,7 +695,6 @@ public ConfigurationClass asConfigClass(ConfigurationClass importedBy) throws IO
695695

696696
public Collection<SourceClass> getMemberClasses() throws IOException {
697697
Object sourceToProcess = this.source;
698-
699698
if (sourceToProcess instanceof Class<?>) {
700699
Class<?> sourceClass = (Class<?>) sourceToProcess;
701700
try {

spring-context/src/main/java/org/springframework/jndi/support/SimpleJndiBeanFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public <T> T getBean(Class<T> requiredType) throws BeansException {
134134
public Object getBean(String name, Object... args) throws BeansException {
135135
if (args != null) {
136136
throw new UnsupportedOperationException(
137-
"SimpleJndiBeanFactory does not support explicit bean creation arguments)");
137+
"SimpleJndiBeanFactory does not support explicit bean creation arguments");
138138
}
139139
return getBean(name);
140140
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2014 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.
@@ -181,8 +181,8 @@ public void setIgnoreUnresolvableNestedPlaceholders(boolean ignoreUnresolvableNe
181181
* @see #setIgnoreUnresolvableNestedPlaceholders
182182
*/
183183
protected String resolveNestedPlaceholders(String value) {
184-
return this.ignoreUnresolvableNestedPlaceholders ?
185-
resolvePlaceholders(value) : resolveRequiredPlaceholders(value);
184+
return (this.ignoreUnresolvableNestedPlaceholders ?
185+
resolvePlaceholders(value) : resolveRequiredPlaceholders(value));
186186
}
187187

188188
private PropertyPlaceholderHelper createPlaceholderHelper(boolean ignoreUnresolvablePlaceholders) {

spring-core/src/main/java/org/springframework/util/PropertyPlaceholderHelper.java

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2014 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.
@@ -62,8 +62,8 @@ public class PropertyPlaceholderHelper {
6262
/**
6363
* Creates a new {@code PropertyPlaceholderHelper} that uses the supplied prefix and suffix.
6464
* Unresolvable placeholders are ignored.
65-
* @param placeholderPrefix the prefix that denotes the start of a placeholder.
66-
* @param placeholderSuffix the suffix that denotes the end of a placeholder.
65+
* @param placeholderPrefix the prefix that denotes the start of a placeholder
66+
* @param placeholderSuffix the suffix that denotes the end of a placeholder
6767
*/
6868
public PropertyPlaceholderHelper(String placeholderPrefix, String placeholderSuffix) {
6969
this(placeholderPrefix, placeholderSuffix, null, true);
@@ -75,14 +75,14 @@ public PropertyPlaceholderHelper(String placeholderPrefix, String placeholderSuf
7575
* @param placeholderSuffix the suffix that denotes the end of a placeholder
7676
* @param valueSeparator the separating character between the placeholder variable
7777
* and the associated default value, if any
78-
* @param ignoreUnresolvablePlaceholders indicates whether unresolvable placeholders should be ignored
79-
* ({@code true}) or cause an exception ({@code false}).
78+
* @param ignoreUnresolvablePlaceholders indicates whether unresolvable placeholders should
79+
* be ignored ({@code true}) or cause an exception ({@code false})
8080
*/
8181
public PropertyPlaceholderHelper(String placeholderPrefix, String placeholderSuffix,
8282
String valueSeparator, boolean ignoreUnresolvablePlaceholders) {
8383

84-
Assert.notNull(placeholderPrefix, "placeholderPrefix must not be null");
85-
Assert.notNull(placeholderSuffix, "placeholderSuffix must not be null");
84+
Assert.notNull(placeholderPrefix, "'placeholderPrefix' must not be null");
85+
Assert.notNull(placeholderSuffix, "'placeholderSuffix' must not be null");
8686
this.placeholderPrefix = placeholderPrefix;
8787
this.placeholderSuffix = placeholderSuffix;
8888
String simplePrefixForSuffix = wellKnownSimplePrefixes.get(this.placeholderSuffix);
@@ -100,12 +100,12 @@ public PropertyPlaceholderHelper(String placeholderPrefix, String placeholderSuf
100100
/**
101101
* Replaces all placeholders of format {@code ${name}} with the corresponding
102102
* property from the supplied {@link Properties}.
103-
* @param value the value containing the placeholders to be replaced.
104-
* @param properties the {@code Properties} to use for replacement.
105-
* @return the supplied value with placeholders replaced inline.
103+
* @param value the value containing the placeholders to be replaced
104+
* @param properties the {@code Properties} to use for replacement
105+
* @return the supplied value with placeholders replaced inline
106106
*/
107107
public String replacePlaceholders(String value, final Properties properties) {
108-
Assert.notNull(properties, "Argument 'properties' must not be null.");
108+
Assert.notNull(properties, "'properties' must not be null");
109109
return replacePlaceholders(value, new PlaceholderResolver() {
110110
@Override
111111
public String resolvePlaceholder(String placeholderName) {
@@ -117,25 +117,25 @@ public String resolvePlaceholder(String placeholderName) {
117117
/**
118118
* Replaces all placeholders of format {@code ${name}} with the value returned
119119
* from the supplied {@link PlaceholderResolver}.
120-
* @param value the value containing the placeholders to be replaced.
121-
* @param placeholderResolver the {@code PlaceholderResolver} to use for replacement.
122-
* @return the supplied value with placeholders replaced inline.
120+
* @param value the value containing the placeholders to be replaced
121+
* @param placeholderResolver the {@code PlaceholderResolver} to use for replacement
122+
* @return the supplied value with placeholders replaced inline
123123
*/
124124
public String replacePlaceholders(String value, PlaceholderResolver placeholderResolver) {
125-
Assert.notNull(value, "Argument 'value' must not be null.");
125+
Assert.notNull(value, "'value' must not be null");
126126
return parseStringValue(value, placeholderResolver, new HashSet<String>());
127127
}
128128

129129
protected String parseStringValue(
130130
String strVal, PlaceholderResolver placeholderResolver, Set<String> visitedPlaceholders) {
131131

132-
StringBuilder buf = new StringBuilder(strVal);
132+
StringBuilder result = new StringBuilder(strVal);
133133

134134
int startIndex = strVal.indexOf(this.placeholderPrefix);
135135
while (startIndex != -1) {
136-
int endIndex = findPlaceholderEndIndex(buf, startIndex);
136+
int endIndex = findPlaceholderEndIndex(result, startIndex);
137137
if (endIndex != -1) {
138-
String placeholder = buf.substring(startIndex + this.placeholderPrefix.length(), endIndex);
138+
String placeholder = result.substring(startIndex + this.placeholderPrefix.length(), endIndex);
139139
String originalPlaceholder = placeholder;
140140
if (!visitedPlaceholders.add(originalPlaceholder)) {
141141
throw new IllegalArgumentException(
@@ -160,15 +160,15 @@ protected String parseStringValue(
160160
// Recursive invocation, parsing placeholders contained in the
161161
// previously resolved placeholder value.
162162
propVal = parseStringValue(propVal, placeholderResolver, visitedPlaceholders);
163-
buf.replace(startIndex, endIndex + this.placeholderSuffix.length(), propVal);
163+
result.replace(startIndex, endIndex + this.placeholderSuffix.length(), propVal);
164164
if (logger.isTraceEnabled()) {
165165
logger.trace("Resolved placeholder '" + placeholder + "'");
166166
}
167-
startIndex = buf.indexOf(this.placeholderPrefix, startIndex + propVal.length());
167+
startIndex = result.indexOf(this.placeholderPrefix, startIndex + propVal.length());
168168
}
169169
else if (this.ignoreUnresolvablePlaceholders) {
170170
// Proceed with unprocessed value.
171-
startIndex = buf.indexOf(this.placeholderPrefix, endIndex + this.placeholderSuffix.length());
171+
startIndex = result.indexOf(this.placeholderPrefix, endIndex + this.placeholderSuffix.length());
172172
}
173173
else {
174174
throw new IllegalArgumentException("Could not resolve placeholder '" +
@@ -181,7 +181,7 @@ else if (this.ignoreUnresolvablePlaceholders) {
181181
}
182182
}
183183

184-
return buf.toString();
184+
return result.toString();
185185
}
186186

187187
private int findPlaceholderEndIndex(CharSequence buf, int startIndex) {
@@ -211,14 +211,13 @@ else if (StringUtils.substringMatch(buf, index, this.simplePrefix)) {
211211

212212
/**
213213
* Strategy interface used to resolve replacement values for placeholders contained in Strings.
214-
* @see PropertyPlaceholderHelper
215214
*/
216215
public static interface PlaceholderResolver {
217216

218217
/**
219-
* Resolves the supplied placeholder name into the replacement value.
218+
* Resolve the supplied placeholder name to the replacement value.
220219
* @param placeholderName the name of the placeholder to resolve
221-
* @return the replacement value or {@code null} if no replacement is to be made
220+
* @return the replacement value, or {@code null} if no replacement is to be made
222221
*/
223222
String resolvePlaceholder(String placeholderName);
224223
}

spring-core/src/test/java/org/springframework/core/env/StandardEnvironmentTests.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,17 @@ public void reservedDefaultProfile() {
204204
System.getProperties().remove(DEFAULT_PROFILES_PROPERTY_NAME);
205205
}
206206

207+
@Test(expected=IllegalArgumentException.class)
208+
public void defaultProfileWithCircularPlaceholder() {
209+
System.setProperty(DEFAULT_PROFILES_PROPERTY_NAME, "${spring.profiles.default}");
210+
try {
211+
environment.getDefaultProfiles();
212+
}
213+
finally {
214+
System.getProperties().remove(DEFAULT_PROFILES_PROPERTY_NAME);
215+
}
216+
}
217+
207218
@Test
208219
public void getActiveProfiles_systemPropertiesEmpty() {
209220
assertThat(environment.getActiveProfiles().length, is(0));

0 commit comments

Comments
 (0)