From ebb19c5816399b83c42b8f9194dbf3d9296975a3 Mon Sep 17 00:00:00 2001
From: Valery Kharseko <vharseko@3a-systems.ru>
Date: Thu, 30 Jul 2026 07:45:56 +0000
Subject: [PATCH] Fix concurrency and equals-contract CodeQL alerts (#785)
---
opendj-server-legacy/src/main/java/org/opends/server/util/cli/PointAdder.java | 31 ++++++++++++++++++++++++-------
1 files changed, 24 insertions(+), 7 deletions(-)
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/util/cli/PointAdder.java b/opendj-server-legacy/src/main/java/org/opends/server/util/cli/PointAdder.java
index ff10a47..e76b6a8 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/util/cli/PointAdder.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/util/cli/PointAdder.java
@@ -13,6 +13,7 @@
*
* Copyright 2010 Sun Microsystems, Inc.
* Portions Copyright 2014-2016 ForgeRock AS.
+ * Portions Copyright 2026 3A Systems, LLC.
*/
package org.opends.server.util.cli;
@@ -26,9 +27,12 @@
public class PointAdder implements Runnable
{
private final ConsoleApplication app;
- private Thread t;
- private boolean stopPointAdder;
- private boolean pointAdderStopped;
+ /** Written by start() and read by stop(), hence volatile. */
+ private volatile Thread t;
+ /** Written by stop() and read by the point adder thread, hence volatile. */
+ private volatile boolean stopPointAdder;
+ /** Written by the point adder thread and read by stop(), hence volatile. */
+ private volatile boolean pointAdderStopped;
private final long periodTime;
private final ProgressMessageFormatter formatter;
@@ -78,20 +82,33 @@
t.start();
}
- /** Stops the PointAdder: points are no longer added at the end of the logs periodically. */
- public synchronized void stop()
+ /**
+ * Stops the PointAdder: points are no longer added at the end of the logs periodically.
+ * <p>
+ * Calling this method on a PointAdder that was never started is a no-op: callers commonly
+ * create the PointAdder before the code path that starts it and stop it from a
+ * {@code finally} block.
+ */
+ public void stop()
{
stopPointAdder = true;
+ final Thread thread = t;
+ if (thread == null)
+ {
+ return;
+ }
while (!pointAdderStopped)
{
+ thread.interrupt();
try
{
- t.interrupt();
// To allow the thread to set the boolean.
Thread.sleep(100);
}
- catch (Throwable t)
+ catch (InterruptedException e)
{
+ Thread.currentThread().interrupt();
+ break;
}
}
}
--
Gitblit v1.10.0