From c6c63ab2f829483e525cee121516ca853979b42a Mon Sep 17 00:00:00 2001 From: Hilbrand Bouwkamp Date: Tue, 28 Jan 2020 21:30:30 +0100 Subject: [PATCH] [innogysmarthome] Added guard against null value (#6920) Fixes #6918 Signed-off-by: Hilbrand Bouwkamp --- .../internal/handler/InnogyBridgeHandler.java | 16 +++++++++++----- .../internal/manager/DeviceStructureManager.java | 4 ++-- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/bundles/org.openhab.binding.innogysmarthome/src/main/java/org/openhab/binding/innogysmarthome/internal/handler/InnogyBridgeHandler.java b/bundles/org.openhab.binding.innogysmarthome/src/main/java/org/openhab/binding/innogysmarthome/internal/handler/InnogyBridgeHandler.java index e1e2cbdf64efb..0a7157eec6dee 100644 --- a/bundles/org.openhab.binding.innogysmarthome/src/main/java/org/openhab/binding/innogysmarthome/internal/handler/InnogyBridgeHandler.java +++ b/bundles/org.openhab.binding.innogysmarthome/src/main/java/org/openhab/binding/innogysmarthome/internal/handler/InnogyBridgeHandler.java @@ -651,7 +651,7 @@ public void handleNewMessageReceivedEvent(final MessageEvent event) logger.trace("Message: {}", gson.toJson(message)); logger.trace("Messagetype: {}", message.getType()); } - if (Message.TYPE_DEVICE_LOW_BATTERY.equals(message.getType())) { + if (Message.TYPE_DEVICE_LOW_BATTERY.equals(message.getType()) && message.getDeviceLinkList() != null) { for (final String link : message.getDeviceLinkList()) { deviceStructMan.refreshDevice(Link.getId(link)); final Device device = deviceStructMan.getDeviceById(Link.getId(link)); @@ -688,11 +688,17 @@ public void handleMessageDeletedEvent(final Event event) throws ApiException, IO logger.debug("handleMessageDeletedEvent with messageId '{}'", messageId); Device device = deviceStructMan.getDeviceWithMessageId(messageId); + if (device != null) { - deviceStructMan.refreshDevice(device.getId()); - device = deviceStructMan.getDeviceById(device.getId()); - for (final DeviceStatusListener deviceStatusListener : deviceStatusListeners) { - deviceStatusListener.onDeviceStateChanged(device); + String id = device.getId(); + deviceStructMan.refreshDevice(id); + device = deviceStructMan.getDeviceById(id); + if (device != null) { + for (final DeviceStatusListener deviceStatusListener : deviceStatusListeners) { + deviceStatusListener.onDeviceStateChanged(device); + } + } else { + logger.debug("No device with id {} found after refresh.", id); } } else { logger.debug("No device found with message id {}.", messageId); diff --git a/bundles/org.openhab.binding.innogysmarthome/src/main/java/org/openhab/binding/innogysmarthome/internal/manager/DeviceStructureManager.java b/bundles/org.openhab.binding.innogysmarthome/src/main/java/org/openhab/binding/innogysmarthome/internal/manager/DeviceStructureManager.java index 8cb1641b2e64a..fd68904a9e0ba 100644 --- a/bundles/org.openhab.binding.innogysmarthome/src/main/java/org/openhab/binding/innogysmarthome/internal/manager/DeviceStructureManager.java +++ b/bundles/org.openhab.binding.innogysmarthome/src/main/java/org/openhab/binding/innogysmarthome/internal/manager/DeviceStructureManager.java @@ -166,7 +166,7 @@ public void addDeviceToStructure(Device device) { * @param id * @return the {@link Device} or null, if it does not exist */ - public Device getDeviceById(String id) { + public @Nullable Device getDeviceById(String id) { logger.debug("getDeviceById {}:{}", id, getDeviceMap().containsKey(id)); return getDeviceMap().get(id); } @@ -177,7 +177,7 @@ public Device getDeviceById(String id) { * @param capabilityId * @return {@link Device} or null */ - public Device getDeviceByCapabilityId(String capabilityId) { + public @Nullable Device getDeviceByCapabilityId(String capabilityId) { return capabilityIdToDeviceMap.get(capabilityId); }