提交 25bc5588 编写于 作者: L lepdou

bugfix: return empty element array when get array property

上级 baba0b56
......@@ -5,6 +5,7 @@ import com.google.common.base.Splitter;
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;
......@@ -90,13 +91,13 @@ public abstract class RefreshableConfig {
}
}
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;
}
}
......
......@@ -43,10 +43,10 @@ public class PortalConfig extends RefreshableConfig {
* 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));
}
......@@ -62,10 +62,10 @@ public class PortalConfig extends RefreshableConfig {
}
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;
}
......
......@@ -39,7 +39,7 @@ public class ConfigTest {
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]);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册