Skip to content

Commit

Permalink
#689 isBeforeFirst/isAfterLast/isFirst/isLast() on a closed result se…
Browse files Browse the repository at this point in the history
…t should throw SQLException
  • Loading branch information
mrotteveel committed Apr 12, 2022
1 parent 7f8072b commit 02f6fa9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/documentation/release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ Jaybird 4.0.6

The following has been changed or fixed since Jaybird 4.0.5

- Improvement: `Connection.isValid(int)` now uses the timeout as a network
timeout, if possible ([jaybird#685](https://github.com/FirebirdSQL/jaybird/issues/685)) \
This is only supported for pure Java connections. For native connections,
the timeout is ignored (and a `SQLWarning` is registered).
- `NativeResourceUnloadWebListener` would fail in Servlet containers with
a `NoClassDefFoundError` if JNA wasn't on the classpath ([jaybird#686](https://github.com/FirebirdSQL/jaybird/issues/686))
- Improvement: `Connection.isValid(int)` now uses the timeout as a network
timeout, if possible ([jaybird#685](https://github.com/FirebirdSQL/jaybird/issues/685)) \
This is only supported for pure Java connections. For native connections,
the timeout is ignored (and a `SQLWarning` is registered).
- `NativeResourceUnloadWebListener` would fail in Servlet containers with
a `NoClassDefFoundError` if JNA wasn't on the classpath ([jaybird#686](https://github.com/FirebirdSQL/jaybird/issues/686))
- Fixed: Calling `isBeforeFirst()`, `isAfterLast()`, `isFirst()`, or `isLast()`
on a closed result set resulted in a `NullPointerException` instead of a
`SQLException` ([jaybird#689](https://github.com/FirebirdSQL/jaybird/issues/689))

Jaybird 4.0.5
-------------
Expand Down
4 changes: 4 additions & 0 deletions src/main/org/firebirdsql/jdbc/AbstractResultSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -872,21 +872,25 @@ public BigDecimal getBigDecimal(String columnName) throws SQLException {

@Override
public boolean isBeforeFirst() throws SQLException {
checkOpen();
return fbFetcher.isBeforeFirst();
}

@Override
public boolean isAfterLast() throws SQLException {
checkOpen();
return fbFetcher.isAfterLast();
}

@Override
public boolean isFirst() throws SQLException {
checkOpen();
return fbFetcher.isFirst();
}

@Override
public boolean isLast() throws SQLException {
checkOpen();
return fbFetcher.isLast();
}

Expand Down
18 changes: 18 additions & 0 deletions src/test/org/firebirdsql/jdbc/TestFBResultSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -1426,6 +1426,24 @@ public void testResultSetUpdateDoesNotNullUntouchedBlob() throws Exception {
}
}

/**
* Rationale: see <a href="https://github.com/FirebirdSQL/jaybird/issues/689">jaybird#689</a>
*/
@Test
public void testIsAfterLast_bug689() throws Exception {
try (Statement stmt = connection.createStatement();
ResultSet resultSet = stmt.executeQuery("select * from RDB$DATABASE")) {

while (resultSet.next()) {
assertFalse("Should not be after last", resultSet.isAfterLast());
}

expectedException.expect(SQLException.class);
expectedException.expectMessage("The result set is closed");
resultSet.isAfterLast();
}
}

private void createTestData(int recordCount) throws SQLException {
try (PreparedStatement ps = connection.prepareStatement(INSERT_INTO_TABLE_STATEMENT)) {
for (int i = 0; i < recordCount; i++) {
Expand Down

0 comments on commit 02f6fa9

Please sign in to comment.