Skip to content

NoSuchElementException in readRandom/readUnique when TG has multiple CSV files with different row counts #31

@amitgour1996

Description

@amitgour1996

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

  1. One Thread Group, two ExtendedCsvDataSetConfig elements:
    • File A: ~1300 rows, selectRow=Random
    • File B: ~2500 rows, selectRow=Unique
  2. Run with multiple threads
  3. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions