Skip to content
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

isAfterLast fails with a null pointer exception where it should return true. #689

Closed
cfnz opened this issue Apr 12, 2022 · 3 comments
Closed

Comments

@cfnz
Copy link

cfnz commented Apr 12, 2022

isAfterLast fails with a null pointer exception where as I think it should return true on the last call (or, worst case, fail with an SQLFeatureNotSupportedException).

Tested on Firebird 3, Jaybird jaybird-jdk18:3.0.12.

Also tested same code on a Postgres DB (query changed appropriately), and it works as expected.

    void quickTest() throws SQLException {
        val connection = DriverManager.getConnection(jdbcUrl, user, password);
        val statement = connection.createStatement();
        val resultSet = statement.executeQuery("select * from RDB$DATABASE");

        while (resultSet.next()) {
            System.out.println("isAfterLast: " + resultSet.isAfterLast());
            System.out.println("RDB$RELATION_ID: " + resultSet.getInt("RDB$RELATION_ID"));
        }
        System.out.println("isAfterLast: " + resultSet.isAfterLast());  // <-- This one raised a null pointer exception
    }
@mrotteveel
Copy link
Member

Thanks for reporting.

The problem is that in auto-commit mode, fetching to the end of the result set will close the result set, which then sets some internal fields null. This should obviously not result in an NPE, but the change I'm going to make will result in a SQLException with text "The result set is closed", and not in isAfterLast() reporting true in auto-commit mode.

This was an explicit requirement in JDBC 3.0 (section 10.1). In JDBC 4.0 this was changed, but closing the result set after fetching the last row (in auto-commit mode) still complies with section 15.2.5 of JDBC 4.3. I will create a separate ticket to see if this should be changed to allow for more flexibility.

Given Jaybird 3.0 is end-of-life, this will only be changed in Jaybird 4 and 5.

@mrotteveel mrotteveel self-assigned this Apr 12, 2022
@mrotteveel
Copy link
Member

Separate ticket to consider changing result set close behaviour in auto-commit is #690

mrotteveel added a commit that referenced this issue Apr 12, 2022
mrotteveel added a commit that referenced this issue Apr 12, 2022
@cfnz
Copy link
Author

cfnz commented Apr 12, 2022

Thanks for your quick response to this query! All the best with the future update 👍

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

No branches or pull requests

2 participants