Bug
When a Thread Group has more than one ExtendedCsvDataSetConfig element and the CSV files have different numbers of rows, threads crash with:
java.util.NoSuchElementException: No value present
at java.base/java.util.Optional.get(Optional.java:143)
at com.di.jmeter.utils.FileServerExtended.readIndexed(FileServerExtended.java:689)
at com.di.jmeter.utils.FileServerExtended.readRandom(FileServerExtended.java:632)
What happens
rowCount in FileServerExtended is a private static int — one value for the whole JVM. Every time calculateRowCount() runs for any CSV, it overwrites this global. So if CSV-A has 1310 rows and CSV-B has 2571 rows, and CSV-B is counted last, rowCount becomes 2571.
When readRandom() runs for CSV-A, it picks a random index up to 2571. But CSV-A only has 1310 lines, so Files.lines(...).skip(pos).findFirst() returns an empty Optional whenever pos > 1310. Calling .get() on that throws NoSuchElementException.
Same problem in readUnique() — it checks currPos < getRowCount() using the global, which may belong to a different file.
How to reproduce
- One Thread Group, two ExtendedCsvDataSetConfig elements:
- File A: ~1300 rows, selectRow=Random
- File B: ~2500 rows, selectRow=Unique
- Run with multiple threads
- Roughly half the iterations on File A crash (probability =
(2571-1310)/2571 ≈ 49%)
Fix
Store rowCount inside the FileEntry inner class (per-file) instead of relying on the shared static. Added getRowCount(String alias) that looks up the correct count by file alias. readRandom() and readUnique() now use this per-file value.
PR with the fix: forthcoming.
Env
- JMeter 5.6.3, Java 21
- di-extended-csv-2.3
Bug
When a Thread Group has more than one
ExtendedCsvDataSetConfigelement and the CSV files have different numbers of rows, threads crash with:What happens
rowCountinFileServerExtendedis aprivate static int— one value for the whole JVM. Every timecalculateRowCount()runs for any CSV, it overwrites this global. So if CSV-A has 1310 rows and CSV-B has 2571 rows, and CSV-B is counted last,rowCountbecomes 2571.When
readRandom()runs for CSV-A, it picks a random index up to 2571. But CSV-A only has 1310 lines, soFiles.lines(...).skip(pos).findFirst()returns an empty Optional wheneverpos > 1310. Calling.get()on that throwsNoSuchElementException.Same problem in
readUnique()— it checkscurrPos < getRowCount()using the global, which may belong to a different file.How to reproduce
(2571-1310)/2571 ≈ 49%)Fix
Store
rowCountinside theFileEntryinner class (per-file) instead of relying on the shared static. AddedgetRowCount(String alias)that looks up the correct count by file alias.readRandom()andreadUnique()now use this per-file value.PR with the fix: forthcoming.
Env