From 1aae0e4826be5e3deffa889977bd7bdb8437af14 Mon Sep 17 00:00:00 2001 From: Achim Kraus Date: Thu, 2 May 2024 18:32:01 +0200 Subject: [PATCH] Handle unexpected exceptions in SystemResourceMonitors. Signed-off-by: Achim Kraus --- .../elements/util/SystemResourceMonitors.java | 31 ++++++++++++++----- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/element-connector/src/main/java/org/eclipse/californium/elements/util/SystemResourceMonitors.java b/element-connector/src/main/java/org/eclipse/californium/elements/util/SystemResourceMonitors.java index 8d4432b907..9abf241d49 100644 --- a/element-connector/src/main/java/org/eclipse/californium/elements/util/SystemResourceMonitors.java +++ b/element-connector/src/main/java/org/eclipse/californium/elements/util/SystemResourceMonitors.java @@ -283,11 +283,16 @@ private synchronized void start() { */ private void checkNow() { if (pending.compareAndSet(false, true)) { - ScheduledFuture future = scheduled.get(); - if (future != null) { - future.cancel(false); + try { + ScheduledFuture future = scheduled.get(); + if (future != null) { + future.cancel(false); + } + resource.checkForUpdate(this); + } catch (RuntimeException ex) { + LOGGER.info("{} unexpected error!", name, ex); + ready(false); } - resource.checkForUpdate(this); } } @@ -296,8 +301,13 @@ private void checkNow() { */ private void check() { if (pending.compareAndSet(false, true)) { - LOGGER.info("{} check for update!", name); - resource.checkForUpdate(this); + try { + LOGGER.info("{} check for update!", name); + resource.checkForUpdate(this); + } catch (RuntimeException ex) { + LOGGER.info("{} unexpected error!", name, ex); + ready(false); + } } else { LOGGER.info("{} check for update pending!", name); } @@ -418,8 +428,13 @@ private MonitoredValues readMonitoredValues() { public void checkForUpdate(SystemResourceCheckReady ready) { MonitoredValues values = readMonitoredValues(); if (this.values.check(values)) { - LOGGER.info("File {} changed!", file); - update(values, ready); + try { + LOGGER.info("File {} changed!", file); + update(values, ready); + } catch (RuntimeException ex) { + ready(values); + throw ex; + } } else { LOGGER.info("File {} unchanged.", file); ready.ready(false);