This is an automated email from the ASF dual-hosted git repository.
elharo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-shared-utils.git
The following commit(s) were added to refs/heads/master by this push:
new 4029554 AbstractStreamHandler.setDone: add notifyAll to wake waiting
threads (#405)
4029554 is described below
commit 4029554bb6cd66ed21ccb3b5b818e3407a731a07
Author: Elliotte Rusty Harold <[email protected]>
AuthorDate: Wed Jul 1 14:16:04 2026 +0000
AbstractStreamHandler.setDone: add notifyAll to wake waiting threads (#405)
---
.../shared/utils/cli/AbstractStreamHandler.java | 3 +-
.../utils/cli/AbstractStreamHandlerTest.java | 55 ++++++++++++++++++++++
2 files changed, 57 insertions(+), 1 deletion(-)
diff --git
a/src/main/java/org/apache/maven/shared/utils/cli/AbstractStreamHandler.java
b/src/main/java/org/apache/maven/shared/utils/cli/AbstractStreamHandler.java
index 97ffb47..7bfea7a 100644
--- a/src/main/java/org/apache/maven/shared/utils/cli/AbstractStreamHandler.java
+++ b/src/main/java/org/apache/maven/shared/utils/cli/AbstractStreamHandler.java
@@ -44,7 +44,8 @@ class AbstractStreamHandler extends Thread {
disabled = true;
}
- protected void setDone() {
+ protected synchronized void setDone() {
done = true;
+ this.notifyAll();
}
}
diff --git
a/src/test/java/org/apache/maven/shared/utils/cli/AbstractStreamHandlerTest.java
b/src/test/java/org/apache/maven/shared/utils/cli/AbstractStreamHandlerTest.java
new file mode 100644
index 0000000..eebe0a2
--- /dev/null
+++
b/src/test/java/org/apache/maven/shared/utils/cli/AbstractStreamHandlerTest.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.shared.utils.cli;
+
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class AbstractStreamHandlerTest {
+ @Test
+ void setDoneNotifiesWaitUntilDone() throws InterruptedException {
+ AbstractStreamHandler handler = new AbstractStreamHandler() {};
+ CountDownLatch waiting = new CountDownLatch(1);
+
+ Thread waiter = new Thread(() -> {
+ try {
+ waiting.countDown();
+ handler.waitUntilDone();
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ }
+ });
+ waiter.start();
+
+ assertTrue(waiting.await(1, TimeUnit.SECONDS), "waiter thread did not
start");
+
+ Thread.sleep(50);
+ assertTrue(waiter.isAlive());
+
+ handler.setDone();
+
+ waiter.join(500);
+ assertFalse(waiter.isAlive());
+ }
+}