From e86998000ec1d95d6f6c8f206fa117db0575e0c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20L=27hopital?= Date: Sun, 20 Aug 2023 18:06:25 +0200 Subject: [PATCH] [openuv] Correcting NPE in IconProvider (#15465) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Gaƫl L'hopital --- .../openuv/internal/OpenUVIconProvider.java | 12 +++++--- .../src/main/resources/icon/uv-index-0.svg | 30 +++++++++++++++++++ 2 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 bundles/org.openhab.binding.openuv/src/main/resources/icon/uv-index-0.svg diff --git a/bundles/org.openhab.binding.openuv/src/main/java/org/openhab/binding/openuv/internal/OpenUVIconProvider.java b/bundles/org.openhab.binding.openuv/src/main/java/org/openhab/binding/openuv/internal/OpenUVIconProvider.java index 4083e6522f3..cb74f035416 100644 --- a/bundles/org.openhab.binding.openuv/src/main/java/org/openhab/binding/openuv/internal/OpenUVIconProvider.java +++ b/bundles/org.openhab.binding.openuv/src/main/java/org/openhab/binding/openuv/internal/OpenUVIconProvider.java @@ -115,10 +115,14 @@ public class OpenUVIconProvider implements IconProvider { String result = ""; URL iconResource = context.getBundle().getEntry("icon/%s.svg".formatted(iconName)); - try (InputStream stream = iconResource.openStream()) { - result = new String(stream.readAllBytes(), StandardCharsets.UTF_8); - } catch (IOException e) { - logger.warn("Unable to load ressource '{}' : {}", iconResource.getPath(), e.getMessage()); + if (iconResource != null) { + try (InputStream stream = iconResource.openStream()) { + result = new String(stream.readAllBytes(), StandardCharsets.UTF_8); + } catch (IOException e) { + logger.warn("Unable to load resource '{}': {}", iconResource.getPath(), e.getMessage()); + } + } else { + logger.warn("Unable to load icon named '{}'", iconName); } return result; } diff --git a/bundles/org.openhab.binding.openuv/src/main/resources/icon/uv-index-0.svg b/bundles/org.openhab.binding.openuv/src/main/resources/icon/uv-index-0.svg new file mode 100644 index 00000000000..11e05be4d62 --- /dev/null +++ b/bundles/org.openhab.binding.openuv/src/main/resources/icon/uv-index-0.svg @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file