mirror of https://github.com/apache/cloudstack.git
framework/config: make logic in ::value() defensive (#9108)
This adds a NPE check on the s_depot.global() which can cause NPE in
case of unit tests, where s_depot is not null but the underlying config
dao is null (not mocked or initialised) via `s_depot.global()` becomes
null.
This reverts commit 5f73172bcb.
Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
This commit is contained in:
parent
5f73172bcb
commit
2a63483b4c
|
|
@ -211,7 +211,7 @@ public class ConfigKey<T> {
|
|||
|
||||
public T value() {
|
||||
if (_value == null || isDynamic()) {
|
||||
ConfigurationVO vo = s_depot != null ? s_depot.global().findById(key()) : null;
|
||||
ConfigurationVO vo = (s_depot != null && s_depot.global() != null) ? s_depot.global().findById(key()) : null;
|
||||
final String value = (vo != null && vo.getValue() != null) ? vo.getValue() : defaultValue();
|
||||
_value = ((value == null) ? (T)defaultValue() : valueOf(value));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ import com.cloud.utils.concurrency.NamedThreadFactory;
|
|||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.util.concurrent.Executors;
|
||||
|
|
@ -59,8 +58,8 @@ public class ConfigKeyScheduledExecutionWrapperTest {
|
|||
@Test(expected = IllegalArgumentException.class)
|
||||
public void invalidConfigKeyTest() {
|
||||
TestRunnable runnable = new TestRunnable();
|
||||
ConfigKey<String> configKey = Mockito.mock(ConfigKey.class);
|
||||
when(configKey.value()).thenReturn("test");
|
||||
ConfigKey<String> configKey = new ConfigKey<>(String.class, "test", "test", "test", "test", true,
|
||||
ConfigKey.Scope.Global, null, null, null, null, null, ConfigKey.Kind.CSV, null);
|
||||
ConfigKeyScheduledExecutionWrapper runner = new ConfigKeyScheduledExecutionWrapper(executorService, runnable, configKey, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue