From e1e5c088af9a7a18444c1faaa00f16c5a3bc6dab Mon Sep 17 00:00:00 2001 From: Nicolas Filotto Date: Sun, 16 Oct 2022 20:14:54 +0200 Subject: [PATCH] Release the read lock in a finally block (#703) --- .../mvnd/common/logging/TerminalOutput.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/common/src/main/java/org/mvndaemon/mvnd/common/logging/TerminalOutput.java b/common/src/main/java/org/mvndaemon/mvnd/common/logging/TerminalOutput.java index c57b63cc6..e5feec211 100644 --- a/common/src/main/java/org/mvndaemon/mvnd/common/logging/TerminalOutput.java +++ b/common/src/main/java/org/mvndaemon/mvnd/common/logging/TerminalOutput.java @@ -469,14 +469,17 @@ void readInputLoop() { try { while (!closing) { if (readInput.readLock().tryLock(10, TimeUnit.MILLISECONDS)) { - int c = terminal.reader().read(10); - if (c == -1) { - break; - } - if (c == KEY_PLUS || c == KEY_MINUS || c == KEY_CTRL_L || c == KEY_CTRL_M || c == KEY_CTRL_B) { - daemonReceive.accept(Message.keyboardInput((char) c)); + try { + int c = terminal.reader().read(10); + if (c == -1) { + break; + } + if (c == KEY_PLUS || c == KEY_MINUS || c == KEY_CTRL_L || c == KEY_CTRL_M || c == KEY_CTRL_B) { + daemonReceive.accept(Message.keyboardInput((char) c)); + } + } finally { + readInput.readLock().unlock(); } - readInput.readLock().unlock(); } } } catch (InterruptedException e) {