Skip to content

Commit

Permalink
bugfix: return empty element array when get array property
Browse files Browse the repository at this point in the history
  • Loading branch information
lepdou committed Dec 22, 2016
1 parent baba0b5 commit 25bc558
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
Expand Up @@ -5,6 +5,7 @@
import com.ctrip.framework.apollo.core.utils.ApolloThreadFactory;
import com.ctrip.framework.apollo.tracer.Tracer;

import com.google.common.base.Strings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -90,13 +91,13 @@ public boolean getBooleanProperty(String key, boolean defaultValue) {
}
}

public String[] getArrayProperty(String key, String defaultValue) {
public String[] getArrayProperty(String key, String[] defaultValue) {
try {
String configuration = getValue(key, defaultValue);
return configuration.split(LIST_SEPARATOR);
String value = getValue(key);
return Strings.isNullOrEmpty(value) ? defaultValue : value.split(LIST_SEPARATOR);
} catch (Exception e) {
Tracer.logError("Get array property failed.", e);
return defaultValue.split(LIST_SEPARATOR);
return defaultValue;
}
}

Expand Down
Expand Up @@ -43,10 +43,10 @@ public List<RefreshablePropertySource> getRefreshablePropertySources() {
* Level: important
**/
public List<Env> portalSupportedEnvs() {
String[] configuration = getArrayProperty("apollo.portal.envs", "FAT,UAT,PRO");
String[] configurations = getArrayProperty("apollo.portal.envs", new String[]{"FAT", "UAT", "PRO"});
List<Env> envs = Lists.newLinkedList();

for (String env : configuration) {
for (String env : configurations) {
envs.add(Env.fromString(env));
}

Expand All @@ -62,10 +62,10 @@ public List<String> superAdmins() {
}

public Set<Env> emailSupportedEnvs() {
String[] configurations = getArrayProperty("email.supported.envs", "");
String[] configurations = getArrayProperty("email.supported.envs", null);

Set<Env> result = Sets.newHashSet();
if (StringUtils.isEmpty(configurations)) {
if (configurations == null || configurations.length == 0) {
return result;
}

Expand Down
Expand Up @@ -39,7 +39,7 @@ public void testGetArrayProperty() {

when(environment.getProperty(testKey)).thenReturn(testValue);

String[] result = config.getArrayProperty(testKey, "");
String[] result = config.getArrayProperty(testKey, null);

Assert.assertEquals(3, result.length);
Assert.assertEquals("a", result[0]);
Expand Down

0 comments on commit 25bc558

Please sign in to comment.