From 56406263d917488fca2ba14ecdd22aad0c899108 Mon Sep 17 00:00:00 2001 From: Andreas Berger Date: Sat, 4 Feb 2023 18:03:14 +0100 Subject: [PATCH] [fineoffsetweatherstation] Fix java.lang.IllegalMonitorStateException (#14326) This fix ensures, that the `ReentrantLock::unlock` method is only called, when the Thread is owning the lock. resolves: #14322 Signed-off-by: Andreas Berger --- .../internal/service/GatewayQueryService.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/bundles/org.openhab.binding.fineoffsetweatherstation/src/main/java/org/openhab/binding/fineoffsetweatherstation/internal/service/GatewayQueryService.java b/bundles/org.openhab.binding.fineoffsetweatherstation/src/main/java/org/openhab/binding/fineoffsetweatherstation/internal/service/GatewayQueryService.java index 94ca5769f3b..498d9bad628 100644 --- a/bundles/org.openhab.binding.fineoffsetweatherstation/src/main/java/org/openhab/binding/fineoffsetweatherstation/internal/service/GatewayQueryService.java +++ b/bundles/org.openhab.binding.fineoffsetweatherstation/src/main/java/org/openhab/binding/fineoffsetweatherstation/internal/service/GatewayQueryService.java @@ -73,14 +73,20 @@ public abstract class GatewayQueryService implements AutoCloseable { protected byte @Nullable [] executeCommand(String command, byte[] request, Function validateResponse) { + try { + if (!REQUEST_LOCK.tryLock(30, TimeUnit.SECONDS)) { + logger.debug("executeCommand({}): timed out while getting the lock", command); + return null; + } + } catch (InterruptedException e) { + logger.debug("executeCommand({}): was interrupted while getting the lock", command); + return null; + } + byte[] buffer = new byte[2028]; int bytesRead; try { - if (!REQUEST_LOCK.tryLock(30, TimeUnit.SECONDS)) { - logger.trace("executeCommand({}): time out while getting lock", command); - return null; - } Socket socket = getConnection(); if (socket == null) { return null;