You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by el...@apache.org on 2026/07/01 12:42:41 UTC

(maven-shared-utils) branch fix/streampollfeeder-volatile created (now c7e8d3a)

This is an automated email from the ASF dual-hosted git repository.

elharo pushed a change to branch fix/streampollfeeder-volatile
in repository https://gitbox.apache.org/repos/asf/maven-shared-utils.git


      at c7e8d3a  StreamPollFeeder: declare done and exception as volatile

This branch includes the following new commits:

     new 01ce767  Add test: StreamPollFeeder with continuous data input
     new c7e8d3a  StreamPollFeeder: declare done and exception as volatile

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(maven-shared-utils) 01/02: Add test: StreamPollFeeder with continuous data input

Posted by el...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

elharo pushed a commit to branch fix/streampollfeeder-volatile
in repository https://gitbox.apache.org/repos/asf/maven-shared-utils.git

commit 01ce767d82875f4a2285bea28b9201c281e97a07
Author: Elliotte Rusty Harold <el...@ibiblio.org>
AuthorDate: Wed Jul 1 08:42:09 2026 -0400

    Add test: StreamPollFeeder with continuous data input
---
 .../shared/utils/cli/StreamPollFeederTest.java     | 31 ++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/src/test/java/org/apache/maven/shared/utils/cli/StreamPollFeederTest.java b/src/test/java/org/apache/maven/shared/utils/cli/StreamPollFeederTest.java
index e1c2475..d2b4f3f 100644
--- a/src/test/java/org/apache/maven/shared/utils/cli/StreamPollFeederTest.java
+++ b/src/test/java/org/apache/maven/shared/utils/cli/StreamPollFeederTest.java
@@ -20,14 +20,45 @@ package org.apache.maven.shared.utils.cli;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.time.Duration;
 
 import org.junit.jupiter.api.Test;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTimeoutPreemptively;
 
 public class StreamPollFeederTest {
 
+    @Test
+    public void waitUntilFeederDoneWithContinuousData() {
+        // Simulates a stream with continuous data where the feeder thread
+        // never enters the synchronized(lock) wait block, so the done
+        // flag must be visible without relying on lock's happens-before.
+        InputStream continuousInput = new InputStream() {
+            @Override
+            public int available() {
+                return 1;
+            }
+
+            @Override
+            public int read() throws IOException {
+                return 0;
+            }
+        };
+
+        assertTimeoutPreemptively(
+                Duration.ofSeconds(5),
+                () -> {
+                    StreamPollFeeder feeder = new StreamPollFeeder(continuousInput, new ByteArrayOutputStream());
+                    feeder.start();
+                    feeder.waitUntilDone();
+                    assertNull(feeder.getException());
+                });
+    }
+
     @Test
     public void waitUntilFeederDoneOnInputStream() throws Exception {
 


(maven-shared-utils) 02/02: StreamPollFeeder: declare done and exception as volatile

Posted by el...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

elharo pushed a commit to branch fix/streampollfeeder-volatile
in repository https://gitbox.apache.org/repos/asf/maven-shared-utils.git

commit c7e8d3aa7f87648e94bf1b88d5815c63d28faec6
Author: Elliotte Rusty Harold <el...@ibiblio.org>
AuthorDate: Wed Jul 1 08:42:30 2026 -0400

    StreamPollFeeder: declare done and exception as volatile
---
 src/main/java/org/apache/maven/shared/utils/cli/StreamPollFeeder.java | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/apache/maven/shared/utils/cli/StreamPollFeeder.java b/src/main/java/org/apache/maven/shared/utils/cli/StreamPollFeeder.java
index 72b16a8..02c36a7 100644
--- a/src/main/java/org/apache/maven/shared/utils/cli/StreamPollFeeder.java
+++ b/src/main/java/org/apache/maven/shared/utils/cli/StreamPollFeeder.java
@@ -35,9 +35,9 @@ class StreamPollFeeder extends Thread {
     private final InputStream input;
     private final OutputStream output;
 
-    private Throwable exception;
+    private volatile Throwable exception;
 
-    private boolean done;
+    private volatile boolean done;
     private final Object lock = new Object();
 
     /**