From 0885d16ac22a0ecd2267bf3c8818a3a8a5a9dadb Mon Sep 17 00:00:00 2001
From: Valery Kharseko <vharseko@3a-systems.ru>
Date: Fri, 31 Jul 2026 07:48:54 +0000
Subject: [PATCH] Fix CodeQL warning-severity alerts: missed wakeups, resource leaks, escaping threads (#790)
---
opendj-server-legacy/src/main/java/org/opends/quicksetup/util/OutputReader.java | 26 ++++++++++++++++++++++----
1 files changed, 22 insertions(+), 4 deletions(-)
diff --git a/opendj-server-legacy/src/main/java/org/opends/quicksetup/util/OutputReader.java b/opendj-server-legacy/src/main/java/org/opends/quicksetup/util/OutputReader.java
index 1a36124..5e0c2e7 100644
--- a/opendj-server-legacy/src/main/java/org/opends/quicksetup/util/OutputReader.java
+++ b/opendj-server-legacy/src/main/java/org/opends/quicksetup/util/OutputReader.java
@@ -13,6 +13,7 @@
*
* Copyright 2008 Sun Microsystems, Inc.
* Portions Copyright 2014-2016 ForgeRock AS.
+ * Portions Copyright 2026 3A Systems, LLC.
*/
package org.opends.quicksetup.util;
@@ -33,18 +34,23 @@
*/
public abstract void processLine(String line);
+ private final Thread thread;
+
/**
* The protected constructor.
+ * <p>
+ * The reader is consumed until end of stream and then closed by this reader's thread, which is
+ * only launched by {@link #start()}.
*
* @param reader the BufferedReader of the stop process.
*/
public OutputReader(final BufferedReader reader) {
- Thread t = new Thread(new Runnable() {
+ thread = new Thread(new Runnable() {
@Override
public void run() {
- try {
+ try (BufferedReader in = reader) {
String line;
- while (null != (line = reader.readLine())) {
+ while (null != (line = in.readLine())) {
processLine(line);
}
} catch (Throwable t) {
@@ -52,6 +58,18 @@
}
}
});
- t.start();
+ }
+
+ /**
+ * Starts consuming the reader in a background thread.
+ * <p>
+ * The thread is not started by the constructor so that {@code this} does not escape before
+ * construction of the subclass has completed.
+ *
+ * @return this reader
+ */
+ public OutputReader start() {
+ thread.start();
+ return this;
}
}
--
Gitblit v1.10.0