Handle previous config being null when setting new config
Handle previous config being null (i.e. not configured before when checking
for unexpected change in config)
@@ -200,12 +200,13 @@ public abstract class ConfigSubscription<T extends ConfigInstance> {
void setConfigAndGeneration(Long generation, boolean applyOnRestart, T config, PayloadChecksums payloadChecksums) {
ConfigState<T> prev = this.config.get();
- boolean configChanged = !Objects.equals(prev.getConfig(), config);
- if (configChanged) {
+ T previousConfig = prev.getConfig();
+ boolean configChanged = ! Objects.equals(previousConfig, config);
+ if (previousConfig != null && configChanged) {
SnippetGenerator generator = new SnippetGenerator();
int sizeHint = 500;
log.log(Level.WARNING, "Config has changed unexpectedly for " + key + ", generation " + generation +
- ", config in state :" + generator.makeSnippet(prev.getConfig().toString(), sizeHint) + ", new config: " +
+ ", config in state :" + generator.makeSnippet(previousConfig.toString(), sizeHint) + ", new config: " +
generator.makeSnippet(config.toString(), sizeHint));
}
this.config.set(new ConfigState<>(true, generation, applyOnRestart, configChanged, config, payloadChecksums));
