[ https://issues.apache.org/jira/browse/CSV-318?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17949955#comment-17949955 ]
Gary D. Gregory edited comment on CSV-318 at 5/7/25 11:06 AM: -------------------------------------------------------------- YW. >From the JavaOne 2025 (or whatever it's called now) talk I've seen on YouTube, >the pinning issues have been resolved. I'll update the other methods to use the same lock. was (Author: garydgregory): YW. >From the JavaOne 2025 (or whatever it's called now) talk I've seen on YouTube, >the pinning issues have been resolved. > 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 > Assignee: Gary D. Gregory > Priority: Major > Fix For: 1.14.1 > > > {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)