When I create a CsvToBean iterator, with throw exception to false, if the first line of CSV file as more than one error, the CsvToBean.iterator() method stay blocked.
In CsvToBeanIterator the capacity of the thrownExceptionsQueue is 1. So, error must be consumed before the next error. But if you choose to avoid throw in order to get errors in other way, the second error of the line wait the first was consumed. The first was never consumed because invocation of
CsvToBean.iterator() was not finished.
Note that if you choose to throw exceptions, the throw append during iterator creation, not in the next call.
The only workaround I have is to override ExceptionHandler and discard all error after the first on the same line.
AtomicLong line = new AtomicLong(-1);
CsvToBean<MyBean> csvToBean = new CsvToBeanBuilder<MyBean>(inputStreamReader)
.withMappingStrategy(strategy)
.withIgnoreLeadingWhiteSpace(true)
.withSeparator(CSV_SEPARATOR)
.withType(CsvReview.class)
.withThrowExceptions(false)
.withExceptionHandler(e -> {
// Workaround
if (e.getLineNumber() > line.getAndSet(e.getLineNumber())) {
return e;
} else {
return null;
}
})
.build();
final Iterator<MyBean> csvReviewIterator = csvToBean.iterator();
Thanks for you attention
Frédéric
I use version 5.3
Oops. Sorry. I'll take a look at it.
Fixed in the next version of opencsv.
Thx 👍
5.4 was released a couple of days ago. Sorry to leave you hanging like that.