Issue
CSVReaderBase.getProgress() can return invalid progress when the split size is zero or the reader has not been initialized with a split size.
Problem
CSVReaderBase.getProgress() divides processedSize by totalSize without checking that totalSize is positive:
|
public long getTotalSize() { |
|
return totalSize; |
|
} |
|
|
@Override
public float getProgress() {
return Math.min(1f, (float) processedSize / (float) totalSize);
}
totalSize is set from the input split length:
|
} catch (InterruptedException ex) { |
|
Thread.currentThread().interrupt(); |
|
throw new IOException("Interrupted Exception thrown while attempting to get split length", ex); |
|
} |
|
} |
|
|
|
/** |
totalSize = genericSplit.getLength() * 4l;
If the split length is zero, or if getProgress() is called before initializeTotalSize(...), this divides by zero.
Expected behavior
Progress should stay in the valid range from 0.0f to 1.0f.
Actual behavior
Progress can become NaN when both processedSize and totalSize are zero, or 1.0f from positive infinity when processedSize is positive and totalSize is zero.
Affected readers
Classes that use or extend CSVReaderBase may be affected, including:
CSVRecordReader
NYCTLCReader
Suggested fix
Return 0.0f when totalSize <= 0. Otherwise, keep the existing capped progress calculation.
Test
Add focused coverage for CSVReaderBase.getProgress() with totalSize=0.
Expected result: progress returns 0.0f and is not NaN.
Issue
CSVReaderBase.getProgress()can return invalid progress when the split size is zero or the reader has not been initialized with a split size.Problem
CSVReaderBase.getProgress()dividesprocessedSizebytotalSizewithout checking thattotalSizeis positive:datawave/warehouse/ingest-csv/src/main/java/datawave/ingest/csv/mr/input/CSVReaderBase.java
Lines 336 to 339 in 02d6867
totalSizeis set from the input split length:datawave/warehouse/ingest-csv/src/main/java/datawave/ingest/csv/mr/input/CSVReaderBase.java
Lines 106 to 112 in 02d6867
If the split length is zero, or if
getProgress()is called beforeinitializeTotalSize(...), this divides by zero.Expected behavior
Progress should stay in the valid range from
0.0fto1.0f.Actual behavior
Progress can become
NaNwhen bothprocessedSizeandtotalSizeare zero, or1.0ffrom positive infinity whenprocessedSizeis positive andtotalSizeis zero.Affected readers
Classes that use or extend
CSVReaderBasemay be affected, including:CSVRecordReaderNYCTLCReaderSuggested fix
Return
0.0fwhentotalSize <= 0. Otherwise, keep the existing capped progress calculation.Test
Add focused coverage for
CSVReaderBase.getProgress()withtotalSize=0.Expected result: progress returns
0.0fand is notNaN.