summaryrefslogtreecommitdiffstats
path: root/container-core
diff options
context:
space:
mode:
authorgjoranv <gv@verizonmedia.com>2021-11-09 15:13:05 +0100
committergjoranv <gv@verizonmedia.com>2021-11-09 15:13:45 +0100
commit088a2b665945ec4b5e9520187c288e0b275989a5 (patch)
tree226b5ecacd63304d0030741bbc9c5904a5d70149 /container-core
parent5bb99556c47fd27d461eee36309483cae97b78d5 (diff)
Throw exception if a config instance is null or missing.
Diffstat (limited to 'container-core')
-rw-r--r--container-core/src/main/java/com/yahoo/container/di/CloudSubscriber.java9
-rw-r--r--container-core/src/main/java/com/yahoo/container/di/componentgraph/core/ComponentNode.java17
2 files changed, 21 insertions, 5 deletions
diff --git a/container-core/src/main/java/com/yahoo/container/di/CloudSubscriber.java b/container-core/src/main/java/com/yahoo/container/di/CloudSubscriber.java
index e751c33b5d0..0247cda8bbd 100644
--- a/container-core/src/main/java/com/yahoo/container/di/CloudSubscriber.java
+++ b/container-core/src/main/java/com/yahoo/container/di/CloudSubscriber.java
@@ -51,7 +51,14 @@ public class CloudSubscriber implements Subscriber {
@Override
public Map<ConfigKey<ConfigInstance>, ConfigInstance> config() {
Map<ConfigKey<ConfigInstance>, ConfigInstance> ret = new HashMap<>();
- handles.forEach((k, v) -> ret.put(k, v.getConfig()));
+ handles.forEach((k, v) -> {
+ ConfigInstance config = v.getConfig();
+ if (config == null) {
+ throw new IllegalArgumentException("Got a null config from the config system for key: " + k +
+ "\nConfig handle: " + v);
+ }
+ ret.put(k, config);
+ });
return ret;
}
diff --git a/container-core/src/main/java/com/yahoo/container/di/componentgraph/core/ComponentNode.java b/container-core/src/main/java/com/yahoo/container/di/componentgraph/core/ComponentNode.java
index c63ad991ab9..bf7366cc60f 100644
--- a/container-core/src/main/java/com/yahoo/container/di/componentgraph/core/ComponentNode.java
+++ b/container-core/src/main/java/com/yahoo/container/di/componentgraph/core/ComponentNode.java
@@ -142,8 +142,8 @@ public class ComponentNode extends Node {
for (Object ob : arguments) {
if (ob instanceof Node) {
actualArguments.add(((Node) ob).component());
- } else if (ob instanceof ConfigKey) {
- actualArguments.add(availableConfigs.get(ob));
+ } else if (ob instanceof ConfigKey<?>) {
+ actualArguments.add(getConfigInstance((ConfigKey<?>)ob));
} else {
actualArguments.add(ob);
}
@@ -214,8 +214,8 @@ public class ComponentNode extends Node {
}
List<ConfigInstance> ret = new ArrayList<>();
for (Object arg : arguments) {
- if (arg instanceof ConfigKey) {
- ret.add(availableConfigs.get(arg));
+ if (arg instanceof ConfigKey<?>) {
+ ret.add(getConfigInstance((ConfigKey<?>)arg));
}
}
return ret;
@@ -240,6 +240,15 @@ public class ComponentNode extends Node {
this.availableConfigs = configs;
}
+ private ConfigInstance getConfigInstance(ConfigKey<?> key) {
+ if (! availableConfigs.containsKey(key))
+ throw new IllegalArgumentException("Config not found in the map of available configs: " + key);
+ else if (availableConfigs.get(key) == null)
+ throw new IllegalStateException("The map of available configs has a null config for: " + key);
+
+ return availableConfigs.get(key);
+ }
+
@Override
public Set<ConfigKey<ConfigInstance>> configKeys() {
return configParameterClasses().stream().map(par -> new ConfigKey<>(par, configId)).collect(Collectors.toSet());