From 005b308cf5cbe739a2a7baa231b562f2cf8734a2 Mon Sep 17 00:00:00 2001 From: Matheus_Maas Date: Sun, 23 Jun 2024 14:15:30 -0300 Subject: [PATCH] Improvement in the next() method of the ResultSetIterator.java class I added an explicit check for resultSet.next(). If there are no more rows, a NoSuchElementException exception is thrown. And I also updated the documentation to include the behavior when there are no more rows in the ResultSet. --- .../java/org/apache/commons/dbutils/ResultSetIterator.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/apache/commons/dbutils/ResultSetIterator.java b/src/main/java/org/apache/commons/dbutils/ResultSetIterator.java index 5f776ff4..134ac2d3 100644 --- a/src/main/java/org/apache/commons/dbutils/ResultSetIterator.java +++ b/src/main/java/org/apache/commons/dbutils/ResultSetIterator.java @@ -95,11 +95,15 @@ public boolean hasNext() { * columns in the {@code ResultSet}. * @see java.util.Iterator#next() * @throws RuntimeException if an SQLException occurs. + * @throws NoSuchElementException if there are no more rows in the {@code ResultSet}. */ @Override public Object[] next() { try { - return resultSet.next() ? this.convert.toArray(resultSet) : new Object[0]; + if (!resultSet.next()) { + throw new NoSuchElementException("No more rows in the ResultSet"); + } + return this.convert.toArray(resultSet); } catch (final SQLException e) { rethrow(e); return null;