From 4480e041375c6c9129c49764a1be598af7cae89a Mon Sep 17 00:00:00 2001 From: Markus Rathgeb Date: Fri, 10 May 2019 09:00:41 +0200 Subject: [PATCH] persistent inbox: do not use incomplete initialized object (#813) Fixes: https://github.com/openhab/openhab-core/issues/812 Signed-off-by: Markus Rathgeb --- .../config/discovery/internal/PersistentInbox.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 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 6337c721e4..96766cb937 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,8 +148,6 @@ public final class PersistentInbox implements Inbox, DiscoveryListener, ThingReg final @Reference ThingRegistry thingRegistry, final @Reference ManagedThingProvider thingProvider, final @Reference ThingTypeRegistry thingTypeRegistry, final @Reference ConfigDescriptionRegistry configDescriptionRegistry) { - this.timeToLiveChecker = ThreadPoolManager.getScheduledPool("discovery") - .scheduleWithFixedDelay(new TimeToLiveCheckingThread(this), 0, 30, TimeUnit.SECONDS); this.discoveryResultStorage = storageService.getStorage(DiscoveryResult.class.getName(), this.getClass().getClassLoader()); this.discoveryServiceRegistry = discoveryServiceRegistry; @@ -159,6 +157,12 @@ public final class PersistentInbox implements Inbox, DiscoveryListener, ThingReg 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 + // already fully instantiated object. + this.timeToLiveChecker = ThreadPoolManager.getScheduledPool("discovery") + .scheduleWithFixedDelay(new TimeToLiveCheckingThread(this), 0, 30, TimeUnit.SECONDS); } @Deactivate