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/server/loggers/AsynchronousTextWriter.java | 20 ++++++++++++++++----
1 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/loggers/AsynchronousTextWriter.java b/opendj-server-legacy/src/main/java/org/opends/server/loggers/AsynchronousTextWriter.java
index fe62576..b64a06e 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/loggers/AsynchronousTextWriter.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/loggers/AsynchronousTextWriter.java
@@ -43,7 +43,7 @@
private String name;
private AtomicBoolean stopRequested;
- private WriterThread writerThread;
+ private final WriterThread writerThread;
private boolean autoFlush;
@@ -65,16 +65,28 @@
this.queue = new LinkedBlockingQueue<>(capacity);
this.capacity = capacity;
- this.writerThread = null;
this.stopRequested = new AtomicBoolean(false);
writerThread = new WriterThread();
- writerThread.start();
DirectoryServer.registerShutdownListener(this);
}
/**
+ * Starts the background thread which publishes the queued log records.
+ * <p>
+ * The thread is not started by the constructor so that {@code this} is not published to it before
+ * construction has completed.
+ *
+ * @return this writer
+ */
+ AsynchronousTextWriter start()
+ {
+ writerThread.start();
+ return this;
+ }
+
+ /**
* The publisher thread is responsible for emptying the queue of log records
* waiting to published.
*/
@@ -216,7 +228,7 @@
stopRequested.set(true);
// Wait for publisher thread to terminate
- while (writerThread != null && writerThread.isAlive()) {
+ while (writerThread.isAlive()) {
try {
// Interrupt the thread if its blocking
writerThread.interrupt();
--
Gitblit v1.10.0