Fix NPE with uninitialized state trackers (#1378)

This fixes a NPE which occurs when a ItemStateChangedEvent
is broadcasted by the ItemStatesSseBroadcaster while some
SseStateEventOutputs haven't initialized their list of
tracked items.

Signed-off-by: Yannick Schaus <github@schaus.net>
This commit is contained in:
Yannick Schaus
2020-02-26 19:18:43 +01:00
committed by GitHub
parent 4258d87d4a
commit 3f48088f94
2 changed files with 3 additions and 3 deletions
@@ -128,8 +128,7 @@ public class ItemStatesSseBroadcaster extends SseBroadcaster {
for (String itemName : itemNames) {
try {
// Check that the item is tracked by at least one connection
if (itemRegistry != null
&& eventOutputs.values().stream().anyMatch(c -> c.getTrackedItems().contains(itemName))) {
if (eventOutputs.values().stream().anyMatch(c -> c.getTrackedItems().contains(itemName))) {
Item item = itemRegistry.getItem(itemName);
StateDTO stateDto = new StateDTO();
stateDto.state = item.getState().toString();
@@ -14,6 +14,7 @@ package org.openhab.core.io.rest.sse.internal;
import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.UUID;
@@ -33,7 +34,7 @@ import org.glassfish.jersey.media.sse.OutboundEvent;
public class SseStateEventOutput extends EventOutput {
private String connectionId;
private Collection<String> trackedItems;
private Collection<String> trackedItems = Collections.emptySet();
public SseStateEventOutput() {
super();