Skip to content

Fixed NPE error when reading CSV file with fewer lines than number of… #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

arthef
Copy link

@arthef arthef commented Apr 8, 2025

If number of lines in the CSV file is lower than number of threads set in the Thread Group csvReadLine throws NPE.
This PR contains a simple fix, tested.

@rollno748
Copy link
Owner

rollno748 commented Apr 8, 2025

Hi @arthef
I am quite confused on the issue, Can you please explain the scenario where it breaks the feature or calculation of threads ?

How does your change of checking line is empty or null will fix it ?

       if (line == null || line.isEmpty())
            return new String[0];

@arthef
Copy link
Author

arthef commented Apr 8, 2025

I am sorry for being too vague. Here is all the information I have:
First the NPE:

2025-04-08 10:47:19,389 INFO o.a.j.t.JMeterThread: Thread finished: Virtual Thread Group 1-8
2025-04-08 10:47:20,384 INFO o.a.j.t.JMeterThread: Thread started: Virtual Thread Group 1-9
2025-04-08 10:47:20,385 ERROR o.a.j.t.JMeterThread: Test failed!
java.lang.NullPointerException: Cannot invoke "String.length()" because "line" is null
        at com.di.jmeter.utils.FileServerExtended.csvReadLine(FileServerExtended.java:725) ~[di-extended-csv-2.3.jar:?]
        at com.di.jmeter.config.ExtendedCsvDataSetConfig.iterationStart(ExtendedCsvDataSetConfig.java:92) ~[di-extended-csv-2.3.jar:?]
        at org.apache.jmeter.control.GenericController.fireIterationStart(GenericController.java:412) ~[ApacheJMeter_core.jar:5.6.3]
        at org.apache.jmeter.control.GenericController.fireIterEvents(GenericController.java:404) ~[ApacheJMeter_core.jar:5.6.3]
        at org.apache.jmeter.control.GenericController.next(GenericController.java:170) ~[ApacheJMeter_core.jar:5.6.3]
        at org.apache.jmeter.control.LoopController.next(LoopController.java:119) ~[ApacheJMeter_core.jar:5.6.3]
        at org.apache.jmeter.threads.AbstractThreadGroup.next(AbstractThreadGroup.java:109) ~[ApacheJMeter_core.jar:5.6.3]
        at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:266) ~[ApacheJMeter_core.jar:5.6.3]
        at java.base/java.lang.VirtualThread.run(VirtualThread.java:329) ~[?:?]

Thread Group settings:

  1. Number of Threads (users): 10
  2. Ramp-up period (seconds): 10
  3. Loop Count: Infinite
  4. Rest settings to OFF

Extended CSV Data Set Config:

  1. Filename: ./test-plans/customers.csv with 4 lines
  2. File encoding: UTF-8
  3. Variable names: useremail,userpassword,userserver,userport,usernotification
  4. Consider first line as variable name: true
  5. Delimiter: ,
  6. Allow quoted data: true
  7. Selected Row: Unique
  8. Update Values: Each Iteration
  9. When out of Values: Continue Cyclic
  10. Sharing Mode: Current Thread Group
  11. Allocate values to thread: Allocate 1 value for each thread

It seems to me, the problem is that there are fewer lines in CSV file than requested threads number. JMeter attempts to allocate data for thread 5 - 10 but there is no more data in the file and NULL is passed as value of the CSV file line to csvReadLine function. Code is not prepared to deal with NULL argument and processing fails with NPE exception.

My change, handles the NULL line the same way as if it was an empty line and does this at the beginning of the function allowing for early/fast return to speed up processing.

Please let me know if you have any questions or if you need more information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants