From 0aaad726ffbae44c53f46d44f523778c235265df Mon Sep 17 00:00:00 2001 From: Markus Rathgeb Date: Thu, 16 May 2019 14:20:50 +0200 Subject: [PATCH] persistent inbox: ensure all members have been set before usage (#826) Fixes #823 Signed-off-by: Markus Rathgeb --- .../config/discovery/internal/PersistentInbox.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/bundles/org.openhab.core.config.discovery/src/main/java/org/eclipse/smarthome/config/discovery/internal/PersistentInbox.java b/bundles/org.openhab.core.config.discovery/src/main/java/org/eclipse/smarthome/config/discovery/internal/PersistentInbox.java index 96766cb93..8c1403274 100644 --- a/bundles/org.openhab.core.config.discovery/src/main/java/org/eclipse/smarthome/config/discovery/internal/PersistentInbox.java +++ b/bundles/org.openhab.core.config.discovery/src/main/java/org/eclipse/smarthome/config/discovery/internal/PersistentInbox.java @@ -148,19 +148,20 @@ public final class PersistentInbox implements Inbox, DiscoveryListener, ThingReg final @Reference ThingRegistry thingRegistry, final @Reference ManagedThingProvider thingProvider, final @Reference ThingTypeRegistry thingTypeRegistry, final @Reference ConfigDescriptionRegistry configDescriptionRegistry) { + // First set all member variables to ensure the object itself is initialized (as most as possible). this.discoveryResultStorage = storageService.getStorage(DiscoveryResult.class.getName(), this.getClass().getClassLoader()); this.discoveryServiceRegistry = discoveryServiceRegistry; - this.discoveryServiceRegistry.addDiscoveryListener(this); this.thingRegistry = thingRegistry; - this.thingRegistry.addRegistryChangeListener(this); this.managedThingProvider = thingProvider; this.thingTypeRegistry = thingTypeRegistry; this.configDescRegistry = configDescriptionRegistry; - // This should be the last step (to be more precise: providing the "this" reference to other ones as long as the - // constructor is not finished is a bad idea at all) as "this" will be used by another thread and so we need + // This should be the last steps (to be more precise: providing the "this" reference to other ones as long as + // the constructor is not finished is a bad idea at all) as "this" will be used by another thread and so we need // already fully instantiated object. + this.discoveryServiceRegistry.addDiscoveryListener(this); + this.thingRegistry.addRegistryChangeListener(this); this.timeToLiveChecker = ThreadPoolManager.getScheduledPool("discovery") .scheduleWithFixedDelay(new TimeToLiveCheckingThread(this), 0, 30, TimeUnit.SECONDS); }