Commit c91f6904 by Jason Song Committed by GitHub

Merge pull request #494 from lepdou/bugfix_1222

bugfix: return empty element array when get array property
parents 451fd882 25bc5588
...@@ -5,6 +5,7 @@ import com.google.common.base.Splitter; ...@@ -5,6 +5,7 @@ import com.google.common.base.Splitter;
import com.ctrip.framework.apollo.core.utils.ApolloThreadFactory; import com.ctrip.framework.apollo.core.utils.ApolloThreadFactory;
import com.ctrip.framework.apollo.tracer.Tracer; import com.ctrip.framework.apollo.tracer.Tracer;
import com.google.common.base.Strings;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -90,13 +91,13 @@ public abstract class RefreshableConfig { ...@@ -90,13 +91,13 @@ public abstract class RefreshableConfig {
} }
} }
public String[] getArrayProperty(String key, String defaultValue) { public String[] getArrayProperty(String key, String[] defaultValue) {
try { try {
String configuration = getValue(key, defaultValue); String value = getValue(key);
return configuration.split(LIST_SEPARATOR); return Strings.isNullOrEmpty(value) ? defaultValue : value.split(LIST_SEPARATOR);
} catch (Exception e) { } catch (Exception e) {
Tracer.logError("Get array property failed.", e); Tracer.logError("Get array property failed.", e);
return defaultValue.split(LIST_SEPARATOR); return defaultValue;
} }
} }
......
...@@ -43,10 +43,10 @@ public class PortalConfig extends RefreshableConfig { ...@@ -43,10 +43,10 @@ public class PortalConfig extends RefreshableConfig {
* Level: important * Level: important
**/ **/
public List<Env> portalSupportedEnvs() { 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(); List<Env> envs = Lists.newLinkedList();
for (String env : configuration) { for (String env : configurations) {
envs.add(Env.fromString(env)); envs.add(Env.fromString(env));
} }
...@@ -62,10 +62,10 @@ public class PortalConfig extends RefreshableConfig { ...@@ -62,10 +62,10 @@ public class PortalConfig extends RefreshableConfig {
} }
public Set<Env> emailSupportedEnvs() { public Set<Env> emailSupportedEnvs() {
String[] configurations = getArrayProperty("email.supported.envs", ""); String[] configurations = getArrayProperty("email.supported.envs", null);
Set<Env> result = Sets.newHashSet(); Set<Env> result = Sets.newHashSet();
if (StringUtils.isEmpty(configurations)) { if (configurations == null || configurations.length == 0) {
return result; return result;
} }
......
...@@ -39,7 +39,7 @@ public class ConfigTest { ...@@ -39,7 +39,7 @@ public class ConfigTest {
when(environment.getProperty(testKey)).thenReturn(testValue); when(environment.getProperty(testKey)).thenReturn(testValue);
String[] result = config.getArrayProperty(testKey, ""); String[] result = config.getArrayProperty(testKey, null);
Assert.assertEquals(3, result.length); Assert.assertEquals(3, result.length);
Assert.assertEquals("a", result[0]); Assert.assertEquals("a", result[0]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment