Skip to content

Commit

Permalink
Warn on empty configurations.
Browse files Browse the repository at this point in the history
Usually occurs, if Californium was already started in other components,
which didn't register the configuration modules properly.

Signed-off-by: Achim Kraus <achim.kraus@cloudcoap.net>
  • Loading branch information
boaks committed Oct 12, 2022
1 parent 3484b9e commit bbd2400
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,27 @@ public T get(String key) {
return definitions.get(key);
}

/**
* Check, if definitions are available.
*
* @return {@code true}, if no definitions are available, {@code false}, if
* definitions are available.
* @since 3.8
*/
public boolean isEmpty() {
return definitions.isEmpty();
}

/**
* Get number of available definitions.
*
* @return number of available definitions.
* @since 3.8
*/
public int size() {
return definitions.size();
}

@Override
public Iterator<T> iterator() {
return definitions.values().iterator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,9 @@ public Configuration() {
this.definitions = DEFAULT_DEFINITIONS;
this.modules = DEFAULT_MODULES;
applyModules();
if (modules.isEmpty() && definitions.isEmpty() && values.isEmpty()) {
LOGGER.warn("Configuration contains no modules, no definitions, and no values!", new Throwable("stacktrace"));
}
}

/**
Expand All @@ -513,6 +516,9 @@ public Configuration(Configuration config) {
: new ConcurrentHashMap<String, Configuration.DefinitionsProvider>(config.modules);
this.transientValues.addAll(config.transientValues);
this.values.putAll(config.values);
if (modules.isEmpty() && definitions.isEmpty() && values.isEmpty()) {
LOGGER.warn("Configuration contains no modules, no definitions, and no values!", new Throwable("stacktrace"));
}
}

/**
Expand All @@ -530,6 +536,9 @@ public Configuration(ModuleDefinitionsProvider... providers) {
}
}
applyModules();
if (modules.isEmpty() && definitions.isEmpty() && values.isEmpty()) {
LOGGER.warn("Configuration contains no modules, no definitions, and no values!", new Throwable("stacktrace"));
}
}

/**
Expand Down

0 comments on commit bbd2400

Please sign in to comment.