From 63bbfb1a9fbf8e2dbfa7d5e529c34aaeb7d39c04 Mon Sep 17 00:00:00 2001 From: Axel Uhl Date: Fri, 14 Jul 2023 22:17:51 +0200 Subject: [PATCH] aftermath to 6ef57221e35d4c6c0afd9d5c05f828439cbdd481: avoiding NPE when waiting for listener thread --- .../markpassingcalculation/MarkPassingCalculator.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/markpassingcalculation/MarkPassingCalculator.java b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/markpassingcalculation/MarkPassingCalculator.java index 0bfb3a9eeff..06d58dfb1c3 100755 --- a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/markpassingcalculation/MarkPassingCalculator.java +++ b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/markpassingcalculation/MarkPassingCalculator.java @@ -200,13 +200,14 @@ public class MarkPassingCalculator { */ public void waitUntilStopped(final long timeoutInMillis) throws InterruptedException { final long start = System.currentTimeMillis(); - if (listenerThread != null) { - synchronized (listenerThread) { + final Thread theListenerThread = listenerThread; + if (theListenerThread != null) { + synchronized (theListenerThread) { while (!listenerThreadStarted && System.currentTimeMillis() - start < timeoutInMillis) { - listenerThread.wait(timeoutInMillis); + theListenerThread.wait(timeoutInMillis); } } - listenerThread.join(timeoutInMillis); + theListenerThread.join(timeoutInMillis); } }