From 9bdc8b2bf8bf5c9c02930000dd5abd4cdbb64003 Mon Sep 17 00:00:00 2001 From: Wouter Born Date: Thu, 23 Sep 2021 17:42:37 +0200 Subject: [PATCH] Prevent NSEE when there is no AddonService The code was already prepared for a nullable default service and then returns a 404 not found. Fixes #2491 Signed-off-by: Wouter Born --- .../io/rest/core/internal/addons/AddonResource.java | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/internal/addons/AddonResource.java b/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/internal/addons/AddonResource.java index 15f4dc96665..13c5114aca3 100644 --- a/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/internal/addons/AddonResource.java +++ b/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/internal/addons/AddonResource.java @@ -275,13 +275,9 @@ private void postFailureEvent(String addonId, @Nullable String msg) { eventPublisher.post(event); } - private AddonService getDefaultService() { - for (AddonService addonService : addonServices) { - if (addonService.getId().equals(DEFAULT_ADDON_SERVICE)) { - return addonService; - } - } - return addonServices.iterator().next(); + private @Nullable AddonService getDefaultService() { + return addonServices.stream().filter(addonService -> DEFAULT_ADDON_SERVICE.equals(addonService.getId())) + .findFirst().orElse(addonServices.stream().findFirst().orElse(null)); } private Stream getAllAddons(Locale locale) {