]> git.basschouten.com Git - openhab-addons.git/commitdiff
[fineoffsetweatherstation] Fix java.lang.IllegalMonitorStateException (#14326)
authorAndreas Berger <Andy2003@users.noreply.github.com>
Sat, 4 Feb 2023 17:03:14 +0000 (18:03 +0100)
committerGitHub <noreply@github.com>
Sat, 4 Feb 2023 17:03:14 +0000 (18:03 +0100)
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 <andreas@berger-freelancer.com>
bundles/org.openhab.binding.fineoffsetweatherstation/src/main/java/org/openhab/binding/fineoffsetweatherstation/internal/service/GatewayQueryService.java

index c60d46a84772043e746ad465421008af80988d02..4edd46dc1526e16ddc5a9273cf249248480b6a18 100644 (file)
@@ -73,14 +73,20 @@ public abstract class GatewayQueryService implements AutoCloseable {
 
     protected byte @Nullable [] executeCommand(String command, byte[] request,
             Function<byte[], Boolean> validateResponse) {
-        byte[] buffer = new byte[2028];
-        int bytesRead;
-
         try {
             if (!REQUEST_LOCK.tryLock(30, TimeUnit.SECONDS)) {
-                logger.trace("executeCommand({}): time out while getting lock", command);
+                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 {
             Socket socket = getConnection();
             if (socket == null) {
                 return null;