The problem is caused by the fact that ucdr (the container for a parsed line) can be null either at the end of the file, or due to a bad line in your file. As your code handles all exceptions caused by a bad line, there's no way to know if ucdr is null because file end was reached or whether a bad line was encountered. What I propose is to use another condition for the loop, one that will be false only if ucdr is null because the end of the file was reached, like this:
boolean continueLooping = true;
do {
try {
ucdr = beanReader.read(ConvergeDataRow.class, headers, processors);
if (ucdr != null) {
rdata.add(ucdr); // contains list of row data.
}
// this line will be skipped when an exception is thrown during
// parsing, but not if the line is successfully handled or on end of
// file .
continueLooping = ucdr != null;
} catch (SuperCsvConstraintViolationException ex) {
logger.log(Level.SEVERE, "NON CORRECT VALUE ENCOUNTERD ON ROW "+beanReader.getRowNumber(), ex);
treatedOk = false;
} catch (SuperCsvCellProcessorException ex){
logger.log(Level.SEVERE, "PARSER EXCEPTION ON ROW "+beanReader.getRowNumber(), ex);
treatedOk = false;
} catch (org.supercsv.exception.SuperCsvException ex){
logger.log(Level.SEVERE, "ERROR ON ROW "+beanReader.getRowNumber(), ex);
treatedOk = false;
}
} while (continueLooping);
treatedOk = true;
Note: treatedOk
being set to true outside the loop looks a bit suspicious...