Skip to content

Commit 5d7b33a

Browse files
authored
Fix null pointer exception when using ConfigKey.Scope.ManagementServer (#3062)
2 parents d0c9a0a + e6149f6 commit 5d7b33a

2 files changed

Lines changed: 54 additions & 1 deletion

File tree

framework/config/src/main/java/org/apache/cloudstack/framework/config/impl/ConfigDepotImpl.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,28 @@ public class ConfigDepotImpl implements ConfigDepot, ConfigDepotAdmin {
7474
List<ScopedConfigStorage> _scopedStorages;
7575
Set<Configurable> _configured = Collections.synchronizedSet(new HashSet<Configurable>());
7676

77-
HashMap<String, Pair<String, ConfigKey<?>>> _allKeys = new HashMap<String, Pair<String, ConfigKey<?>>>(1007);
77+
private HashMap<String, Pair<String, ConfigKey<?>>> _allKeys = new HashMap<String, Pair<String, ConfigKey<?>>>(1007);
7878

7979
HashMap<ConfigKey.Scope, Set<ConfigKey<?>>> _scopeLevelConfigsMap = new HashMap<ConfigKey.Scope, Set<ConfigKey<?>>>();
8080

8181
public ConfigDepotImpl() {
8282
ConfigKey.init(this);
83+
createEmptyScopeLevelMappings();
84+
}
85+
86+
/**
87+
* Create an empty map of ConfigKey.Scope values, setting the _scopeLevelConfigsMap with the created map
88+
* This map must contain all ConfigKey.Scope values, except the ConfigKey.Scope.Global.
89+
*/
90+
protected void createEmptyScopeLevelMappings() {
91+
_scopeLevelConfigsMap = new HashMap<ConfigKey.Scope, Set<ConfigKey<?>>>();
8392
_scopeLevelConfigsMap.put(ConfigKey.Scope.Zone, new HashSet<ConfigKey<?>>());
8493
_scopeLevelConfigsMap.put(ConfigKey.Scope.Cluster, new HashSet<ConfigKey<?>>());
8594
_scopeLevelConfigsMap.put(ConfigKey.Scope.StoragePool, new HashSet<ConfigKey<?>>());
8695
_scopeLevelConfigsMap.put(ConfigKey.Scope.Account, new HashSet<ConfigKey<?>>());
8796
_scopeLevelConfigsMap.put(ConfigKey.Scope.ImageStore, new HashSet<ConfigKey<?>>());
8897
_scopeLevelConfigsMap.put(ConfigKey.Scope.Domain, new HashSet<ConfigKey<?>>());
98+
_scopeLevelConfigsMap.put(ConfigKey.Scope.ManagementServer, new HashSet<ConfigKey<?>>());
8999
}
90100

91101
@Override
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//
2+
// Licensed to the Apache Software Foundation (ASF) under one
3+
// or more contributor license agreements. See the NOTICE file
4+
// distributed with this work for additional information
5+
// regarding copyright ownership. The ASF licenses this file
6+
// to you under the Apache License, Version 2.0 (the
7+
// "License"); you may not use this file except in compliance
8+
// with the License. You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing,
13+
// software distributed under the License is distributed on an
14+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
// KIND, either express or implied. See the License for the
16+
// specific language governing permissions and limitations
17+
// under the License.
18+
//
19+
package org.apache.cloudstack.framework.config.impl;
20+
21+
import org.apache.cloudstack.framework.config.ConfigKey;
22+
import org.junit.Assert;
23+
import org.junit.Test;
24+
25+
public class ConfigDepotImplTest {
26+
27+
private ConfigDepotImpl configDepotImpl = new ConfigDepotImpl();
28+
29+
@Test
30+
public void createEmptyScopeLevelMappingsTest() {
31+
configDepotImpl.createEmptyScopeLevelMappings();
32+
ConfigKey.Scope[] configKeyScopeArray = ConfigKey.Scope.values();
33+
34+
for (int i = 0; i < configKeyScopeArray.length; i++) {
35+
if (configKeyScopeArray[i] == ConfigKey.Scope.Global) {
36+
Assert.assertFalse(configDepotImpl._scopeLevelConfigsMap.containsKey(configKeyScopeArray[i]));
37+
} else {
38+
Assert.assertTrue(configDepotImpl._scopeLevelConfigsMap.containsKey(configKeyScopeArray[i]));
39+
}
40+
}
41+
}
42+
43+
}

0 commit comments

Comments
 (0)