From f9866b2c7770511cb8fa768bdde77fbf8f55e892 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=A9tan=20Collaud?= Date: Sat, 5 Dec 2020 01:06:59 +0100 Subject: [PATCH] [digitalstrom] fixes StringIndexOutOfBoundsException (#9194) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [digitalstrom] catch issues when adding devices Signed-off-by: Gaétan Collaud * Update bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/discovery/DiscoveryServiceManager.java Signed-off-by: Gaétan Collaud --- .../discovery/DiscoveryServiceManager.java | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/discovery/DiscoveryServiceManager.java b/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/discovery/DiscoveryServiceManager.java index 7866ed6e8..187d71bac 100644 --- a/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/discovery/DiscoveryServiceManager.java +++ b/bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/discovery/DiscoveryServiceManager.java @@ -40,6 +40,8 @@ import org.openhab.core.thing.ThingTypeUID; import org.openhab.core.thing.type.ThingType; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceRegistration; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * The {@link DiscoveryServiceManager} manages the different scene and device discovery services and informs them about @@ -51,6 +53,8 @@ import org.osgi.framework.ServiceRegistration; public class DiscoveryServiceManager implements SceneStatusListener, DeviceStatusListener, TemperatureControlStatusListener { + private final Logger logger = LoggerFactory.getLogger(DiscoveryServiceManager.class); + private final Map discoveryServices; private final Map> discoveryServiceRegs = new HashMap<>(); private final String bridgeUID; @@ -194,20 +198,25 @@ public class DiscoveryServiceManager @Override public void onDeviceAdded(GeneralDeviceInformation device) { - if (device instanceof Device) { - String id = ((Device) device).getHWinfo().substring(0, 2); - if (((Device) device).isSensorDevice()) { - id = ((Device) device).getHWinfo(); + try { + if (device instanceof Device) { + String id = ((Device) device).getHWinfo().substring(0, 2); + if (((Device) device).isSensorDevice()) { + id = ((Device) device).getHWinfo(); + } + if (discoveryServices.get(id) != null) { + ((DeviceDiscoveryService) discoveryServices.get(id)).onDeviceAdded(device); + } } - if (discoveryServices.get(id) != null) { - ((DeviceDiscoveryService) discoveryServices.get(id)).onDeviceAdded(device); - } - } - if (device instanceof Circuit) { - if (discoveryServices.get(DsDeviceThingTypeProvider.SupportedThingTypes.circuit.toString()) != null) { - ((DeviceDiscoveryService) discoveryServices - .get(DsDeviceThingTypeProvider.SupportedThingTypes.circuit.toString())).onDeviceAdded(device); + if (device instanceof Circuit) { + if (discoveryServices.get(DsDeviceThingTypeProvider.SupportedThingTypes.circuit.toString()) != null) { + ((DeviceDiscoveryService) discoveryServices + .get(DsDeviceThingTypeProvider.SupportedThingTypes.circuit.toString())) + .onDeviceAdded(device); + } } + } catch (RuntimeException ex) { + logger.warn("Unable to add devices {}", device, ex); } }