Skip to content

Commit bc06ffb

Browse files
committed
removed obsolete System.err logging for the property-not-found case
1 parent 5e68cc5 commit bc06ffb

File tree

1 file changed

+21
-27
lines changed

1 file changed

+21
-27
lines changed

org.springframework.core/src/main/java/org/springframework/util/SystemPropertyUtils.java

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@
2626
* and value.
2727
*
2828
* @author Juergen Hoeller
29+
* @author Rob Harrop
2930
* @author Dave Syer
31+
* @since 1.2.5
3032
* @see #PLACEHOLDER_PREFIX
3133
* @see #PLACEHOLDER_SUFFIX
3234
* @see System#getProperty(String)
33-
* @since 1.2.5
3435
*/
3536
public abstract class SystemPropertyUtils {
3637

@@ -43,19 +44,20 @@ public abstract class SystemPropertyUtils {
4344
/** Value separator for system property placeholders: ":" */
4445
public static final String VALUE_SEPARATOR = ":";
4546

46-
private static final PropertyPlaceholderHelper strictHelper = new PropertyPlaceholderHelper(PLACEHOLDER_PREFIX,
47-
PLACEHOLDER_SUFFIX, VALUE_SEPARATOR, false);
4847

49-
private static final PropertyPlaceholderHelper nonStrictHelper = new PropertyPlaceholderHelper(PLACEHOLDER_PREFIX,
50-
PLACEHOLDER_SUFFIX, VALUE_SEPARATOR, true);
48+
private static final PropertyPlaceholderHelper strictHelper =
49+
new PropertyPlaceholderHelper(PLACEHOLDER_PREFIX, PLACEHOLDER_SUFFIX, VALUE_SEPARATOR, false);
50+
51+
private static final PropertyPlaceholderHelper nonStrictHelper =
52+
new PropertyPlaceholderHelper(PLACEHOLDER_PREFIX, PLACEHOLDER_SUFFIX, VALUE_SEPARATOR, true);
53+
5154

5255
/**
5356
* Resolve ${...} placeholders in the given text, replacing them with corresponding system property values.
5457
* @param text the String to resolve
5558
* @return the resolved String
5659
* @see #PLACEHOLDER_PREFIX
5760
* @see #PLACEHOLDER_SUFFIX
58-
*
5961
* @throws IllegalArgumentException if there is an unresolvable placeholder
6062
*/
6163
public static String resolvePlaceholders(final String text) {
@@ -66,49 +68,41 @@ public static String resolvePlaceholders(final String text) {
6668
* Resolve ${...} placeholders in the given text, replacing them with corresponding system property values.
6769
* Unresolvable placeholders with no default value are ignored and passed through unchanged if the
6870
* flag is set to true.
69-
*
7071
* @param text the String to resolve
7172
* @param ignoreUnresolvablePlaceholders flag to determine is unresolved placeholders are ignored
7273
* @return the resolved String
7374
* @see #PLACEHOLDER_PREFIX
7475
* @see #PLACEHOLDER_SUFFIX
75-
*
7676
* @throws IllegalArgumentException if there is an unresolvable placeholder and the flag is false
77-
*
7877
*/
7978
public static String resolvePlaceholders(final String text, boolean ignoreUnresolvablePlaceholders) {
80-
if (ignoreUnresolvablePlaceholders) {
81-
return nonStrictHelper.replacePlaceholders(text, new PlaceholderResolverImplementation(text));
82-
}
83-
return strictHelper.replacePlaceholders(text, new PlaceholderResolverImplementation(text));
79+
PropertyPlaceholderHelper helper = (ignoreUnresolvablePlaceholders ? nonStrictHelper : strictHelper);
80+
return helper.replacePlaceholders(text, new SystemPropertyPlaceholderResolver(text));
8481
}
8582

86-
private static final class PlaceholderResolverImplementation implements PlaceholderResolver {
83+
84+
private static class SystemPropertyPlaceholderResolver implements PlaceholderResolver {
85+
8786
private final String text;
8887

89-
private PlaceholderResolverImplementation(String text) {
88+
public SystemPropertyPlaceholderResolver(String text) {
9089
this.text = text;
9190
}
9291

9392
public String resolvePlaceholder(String placeholderName) {
94-
String propVal = null;
9593
try {
96-
propVal = System.getProperty(placeholderName);
94+
String propVal = System.getProperty(placeholderName);
9795
if (propVal == null) {
9896
// Fall back to searching the system environment.
9997
propVal = System.getenv(placeholderName);
10098
}
101-
102-
if (propVal == null) {
103-
System.err.println("Could not resolve placeholder '" + placeholderName + "' in [" + text
104-
+ "] as system property: neither system property nor environment variable found");
105-
}
106-
} catch (Throwable ex) {
107-
System.err.println("Could not resolve placeholder '" + placeholderName + "' in [" + text
108-
+ "] as system property: " + ex);
109-
99+
return propVal;
100+
}
101+
catch (Throwable ex) {
102+
System.err.println("Could not resolve placeholder '" + placeholderName + "' in [" +
103+
this.text + "] as system property: " + ex);
104+
return null;
110105
}
111-
return propVal;
112106
}
113107
}
114108

0 commit comments

Comments
 (0)