[
https://issues.apache.org/jira/browse/CSV-318?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Gary D. Gregory updated CSV-318:
--------------------------------
Summary: CSVPrinter.printRecord(Stream) hangs if given a parallel stream
(was: printRecord() hangs if given a parallel stream)
> CSVPrinter.printRecord(Stream) hangs if given a parallel stream
> ---------------------------------------------------------------
>
> Key: CSV-318
> URL: https://issues.apache.org/jira/browse/CSV-318
> Project: Commons CSV
> Issue Type: Bug
> Components: Printer
> Affects Versions: 1.14.0
> Environment: {color:#000000}openjdk version "21.0.6"
> 2025-01-21{color}{color:#000000} {color}
> {color:#000000}OpenJDK Runtime Environment (Red_Hat-21.0.6.0.7-1) (build
> 21.0.6+7){color}{color:#000000} {color}
> {color:#000000}OpenJDK 64-Bit Server VM (Red_Hat-21.0.6.0.7-1) (build
> 21.0.6+7, mixed mode, sharing){color}
> {color:#000000} {color}
> Reporter: Joseph Shraibman
> Priority: Major
>
> {code:java}
> import org.apache.commons.csv.CSVFormat;
> import org.apache.commons.csv.CSVPrinter;
> import org.junit.jupiter.api.Test;
> import java.io.ByteArrayOutputStream;
> import java.io.IOException;
> import java.io.PrintWriter;
> public class CommonsCsvTest {
> @Test
> void testWithParStream() throws IOException {
> ByteArrayOutputStream baos = new ByteArrayOutputStream();
> try(CSVPrinter printer = new CSVPrinter(new PrintWriter(baos),
> CSVFormat.DEFAULT)){
> printer.printRecord(java.util.stream.Stream.of("col a", "col b",
> "col c").parallel());
> }
> }
> @Test
> void testWithSeqStream() throws IOException {
> ByteArrayOutputStream baos = new ByteArrayOutputStream();
> try(CSVPrinter printer = new CSVPrinter(new PrintWriter(baos),
> CSVFormat.DEFAULT)){
> printer.printRecord(java.util.stream.Stream.of("col a", "col b",
> "col c"));
> }
> }
> }
> {code}
> A simple workaround is to call sequential() on any passed in Stream.
> I don't know why this is happening. At first I thought it must be a problem
> with the underlying Stream implementation but this code has no problem:
>
> {code:java}
> @Test
> void testJavaStream(){
> java.util.stream.Stream.of("col a", "col b", "col c").parallel()
> .forEachOrdered(System.out::println);
> }{code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)