From 75e51119faa720d231d46a89bba7f0b4391852f3 Mon Sep 17 00:00:00 2001 From: Jacob Laursen Date: Thu, 5 Oct 2023 14:54:04 +0200 Subject: [PATCH] [energidataservice] Fix IllegalStateException (#15693) Signed-off-by: Jacob Laursen --- .../internal/CacheManager.java | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/bundles/org.openhab.binding.energidataservice/src/main/java/org/openhab/binding/energidataservice/internal/CacheManager.java b/bundles/org.openhab.binding.energidataservice/src/main/java/org/openhab/binding/energidataservice/internal/CacheManager.java index 3e95bf67e82..64bae83d589 100644 --- a/bundles/org.openhab.binding.energidataservice/src/main/java/org/openhab/binding/energidataservice/internal/CacheManager.java +++ b/bundles/org.openhab.binding.energidataservice/src/main/java/org/openhab/binding/energidataservice/internal/CacheManager.java @@ -50,10 +50,9 @@ public class CacheManager { private final Clock clock; private final PriceListParser priceListParser = new PriceListParser(); - private Map> datahubRecordsMap = new HashMap<>(); - private Map spotPriceMap = new ConcurrentHashMap<>(SPOT_PRICE_MAX_CACHE_SIZE); + private Map> datahubRecordsMap = new HashMap<>(); private Map> tariffsMap = new ConcurrentHashMap<>(); public CacheManager() { @@ -63,9 +62,9 @@ public class CacheManager { public CacheManager(Clock clock) { this.clock = clock.withZone(NORD_POOL_TIMEZONE); - for (DatahubTariff tariff : DatahubTariff.values()) { - datahubRecordsMap.put(tariff, new ArrayList<>()); - tariffsMap.put(tariff, new ConcurrentHashMap<>(TARIFF_MAX_CACHE_SIZE)); + for (DatahubTariff datahubTariff : DatahubTariff.values()) { + datahubRecordsMap.put(datahubTariff, new ArrayList<>()); + tariffsMap.put(datahubTariff, new ConcurrentHashMap<>(TARIFF_MAX_CACHE_SIZE)); } } @@ -73,9 +72,19 @@ public class CacheManager { * Clear all cached data. */ public void clear() { - datahubRecordsMap.clear(); spotPriceMap.clear(); - tariffsMap.clear(); + + for (DatahubTariff datahubTariff : DatahubTariff.values()) { + Collection datahubRecords = datahubRecordsMap.get(datahubTariff); + if (datahubRecords != null) { + datahubRecords.clear(); + } + + Map tariffs = tariffsMap.get(datahubTariff); + if (tariffs != null) { + tariffs.clear(); + } + } } /**