Skip to content

Commit 39a2366

Browse files
committed
PropertySource implementations perform conversion to String arrays via StringUtils (getting rid of EMPTY_NAMES_ARRAY)
(cherry picked from commit b73c531)
1 parent 25971d9 commit 39a2366

File tree

7 files changed

+26
-21
lines changed

7 files changed

+26
-21
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
*/
4646
public abstract class EnumerablePropertySource<T> extends PropertySource<T> {
4747

48+
@Deprecated
4849
protected static final String[] EMPTY_NAMES_ARRAY = new String[0];
4950

5051
protected final Log logger = LogFactory.getLog(getClass());

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2011 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.
@@ -18,6 +18,8 @@
1818

1919
import java.util.Map;
2020

21+
import org.springframework.util.StringUtils;
22+
2123
/**
2224
* {@link PropertySource} that reads keys and values from a {@code Map} object.
2325
*
@@ -38,7 +40,7 @@ public Object getProperty(String name) {
3840

3941
@Override
4042
public String[] getPropertyNames() {
41-
return this.source.keySet().toArray(EMPTY_NAMES_ARRAY);
43+
return StringUtils.toStringArray(this.source.keySet());
4244
}
4345

4446
}

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 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.
@@ -21,6 +21,7 @@
2121

2222
import org.apache.commons.logging.Log;
2323
import org.apache.commons.logging.LogFactory;
24+
2425
import org.springframework.util.Assert;
2526
import org.springframework.util.StringUtils;
2627

@@ -66,7 +67,7 @@ public MutablePropertySources(PropertySources propertySources) {
6667
}
6768

6869
/**
69-
* Create a new {@link MutablePropertySources} object and inheriting the given logger,
70+
* Create a new {@link MutablePropertySources} object and inherit the given logger,
7071
* usually from an enclosing {@link Environment}.
7172
*/
7273
MutablePropertySources(Log logger) {
@@ -130,7 +131,7 @@ public void addBefore(String relativePropertySourceName, PropertySource<?> prope
130131
}
131132

132133
/**
133-
* Add the given property source object with precedence immediately lower than
134+
* Add the given property source object with precedence immediately lower
134135
* than the named relative property source.
135136
*/
136137
public void addAfter(String relativePropertySourceName, PropertySource<?> propertySource) {
@@ -187,7 +188,7 @@ public int size() {
187188
}
188189

189190
@Override
190-
public synchronized String toString() {
191+
public String toString() {
191192
String[] names = new String[this.size()];
192193
for (int i=0; i < size(); i++) {
193194
names[i] = this.propertySourceList.get(i).getName();
@@ -205,7 +206,7 @@ protected void assertLegalRelativeAddition(String relativePropertySourceName, Pr
205206
}
206207

207208
/**
208-
* Log the removal of the given propertySource if it is present.
209+
* Remove the given property source if it is present.
209210
*/
210211
protected void removeIfPresent(PropertySource<?> propertySource) {
211212
if (this.propertySourceList.contains(propertySource)) {

spring-web/src/main/java/org/springframework/web/context/support/ServletConfigPropertySource.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2011 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.
@@ -20,7 +20,7 @@
2020

2121
import org.springframework.core.env.EnumerablePropertySource;
2222
import org.springframework.core.env.PropertySource;
23-
import org.springframework.util.CollectionUtils;
23+
import org.springframework.util.StringUtils;
2424

2525
/**
2626
* {@link PropertySource} that reads init parameters from a {@link ServletConfig} object.
@@ -37,8 +37,7 @@ public ServletConfigPropertySource(String name, ServletConfig servletConfig) {
3737

3838
@Override
3939
public String[] getPropertyNames() {
40-
return CollectionUtils.toArray(
41-
this.source.getInitParameterNames(), EMPTY_NAMES_ARRAY);
40+
return StringUtils.toStringArray(this.source.getInitParameterNames());
4241
}
4342

4443
@Override

spring-web/src/main/java/org/springframework/web/context/support/ServletContextPropertySource.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 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.
@@ -20,7 +20,7 @@
2020

2121
import org.springframework.core.env.EnumerablePropertySource;
2222
import org.springframework.core.env.PropertySource;
23-
import org.springframework.util.CollectionUtils;
23+
import org.springframework.util.StringUtils;
2424

2525
/**
2626
* {@link PropertySource} that reads init parameters from a {@link ServletContext} object.
@@ -37,12 +37,12 @@ public ServletContextPropertySource(String name, ServletContext servletContext)
3737

3838
@Override
3939
public String[] getPropertyNames() {
40-
return CollectionUtils.toArray(
41-
this.source.getInitParameterNames(), EMPTY_NAMES_ARRAY);
40+
return StringUtils.toStringArray(this.source.getInitParameterNames());
4241
}
4342

4443
@Override
4544
public String getProperty(String name) {
4645
return this.source.getInitParameter(name);
4746
}
47+
4848
}

spring-webmvc-portlet/src/main/java/org/springframework/web/portlet/context/PortletConfigPropertySource.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2011 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.
@@ -20,7 +20,7 @@
2020

2121
import org.springframework.core.env.EnumerablePropertySource;
2222
import org.springframework.core.env.PropertySource;
23-
import org.springframework.util.CollectionUtils;
23+
import org.springframework.util.StringUtils;
2424

2525
/**
2626
* {@link PropertySource} that reads init parameters from a {@link PortletConfig} object.
@@ -37,11 +37,12 @@ public PortletConfigPropertySource(String name, PortletConfig portletConfig) {
3737

3838
@Override
3939
public String[] getPropertyNames() {
40-
return CollectionUtils.toArray(this.source.getInitParameterNames(), EMPTY_NAMES_ARRAY);
40+
return StringUtils.toStringArray(this.source.getInitParameterNames());
4141
}
4242

4343
@Override
4444
public String getProperty(String name) {
4545
return this.source.getInitParameter(name);
4646
}
47+
4748
}

spring-webmvc-portlet/src/main/java/org/springframework/web/portlet/context/PortletContextPropertySource.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2011 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.
@@ -20,7 +20,7 @@
2020

2121
import org.springframework.core.env.EnumerablePropertySource;
2222
import org.springframework.core.env.PropertySource;
23-
import org.springframework.util.CollectionUtils;
23+
import org.springframework.util.StringUtils;
2424

2525
/**
2626
* {@link PropertySource} that reads init parameters from a {@link PortletContext} object.
@@ -37,11 +37,12 @@ public PortletContextPropertySource(String name, PortletContext portletContext)
3737

3838
@Override
3939
public String[] getPropertyNames() {
40-
return CollectionUtils.toArray(this.source.getInitParameterNames(), EMPTY_NAMES_ARRAY);
40+
return StringUtils.toStringArray(this.source.getInitParameterNames());
4141
}
4242

4343
@Override
4444
public String getProperty(String name) {
4545
return this.source.getInitParameter(name);
4646
}
47+
4748
}

0 commit comments

Comments
 (0)