vlsi commented on code in PR #6694:
URL: https://github.com/apache/jmeter/pull/6694#discussion_r3110778815
##########
src/functions/src/main/java/org/apache/jmeter/functions/FileRowColContainer.java:
##########
@@ -119,13 +120,18 @@ public String getColumn(int row, int col) throws
IndexOutOfBoundsException {
*
*/
public int nextRow() {
- int row = nextRow;
- nextRow++;
- if (nextRow >= fileData.size()) {// 0-based
- nextRow = 0;
+ int size = fileData.size();
+ if (size <= 0) {
+ throw new IllegalStateException("CSV file has no data rows");
+ }
+ while (true) {
+ int current = nextRow.get();
+ int next = (current + 1) % size;
Review Comment:
WDYT of going with `AtomicLong.getAndIncrement` and
`java.lang.Math#floorMod(long, int)`?
Then it could work without a loop.
E.g.
```java
private final AtomicLong nextRow = new AtomicLong();
long row = nextRow.getAndIncrement();
int result = (int) Math.floorMod(row, size);
```
##########
src/functions/src/main/java/org/apache/jmeter/functions/FileRowColContainer.java:
##########
@@ -119,13 +120,18 @@ public String getColumn(int row, int col) throws
IndexOutOfBoundsException {
*
*/
public int nextRow() {
- int row = nextRow;
- nextRow++;
- if (nextRow >= fileData.size()) {// 0-based
- nextRow = 0;
+ int size = fileData.size();
+ if (size <= 0) {
+ throw new IllegalStateException("CSV file has no data rows");
Review Comment:
Please include the file name, otherwise it would be hard to troubleshoot. An
alternative option would be returning 0 and making sure the caller would throw
an appropriate error with the file name of the problematic file.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]