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

NPE bug while doing an update operation #948

Closed
razvanmihaescu opened this issue Aug 10, 2023 · 4 comments
Closed

NPE bug while doing an update operation #948

razvanmihaescu opened this issue Aug 10, 2023 · 4 comments
Labels
waiting for feedback Waiting for a feedback from the issue creator

Comments

@razvanmihaescu
Copy link

razvanmihaescu commented Aug 10, 2023

Hello

I discovered that with the latest 2 versions of org.xerial:sqlite-jdbc -> 3.41.2.2 & 3.42.0.0, if the first new value of an update operation is null, the update itself crashes with a NPE, the issue is occuring only in this case, if the null value is for the first parameter, any index works fine.

Here is the stack trace:

xception: nullntat org.sqlite.core.CoreStatement.checkIndex(CoreStatement.java:145)ntat org.sqlite.jdbc3.JDBC3PreparedStatement.getParameterType(JDBC3PreparedStatement.java:165)ntat org.springframework.jdbc.core.StatementCreatorUtils.setNull(StatementCreatorUtils.java:253)ntat org.springframework.jdbc.core.StatementCreatorUtils.setParameterValueInternal(StatementCreatorUtils.java:234)ntat org.springframework.jdbc.core.StatementCreatorUtils.setParameterValue(StatementCreatorUtils.java:168)ntat org.springframework.jdbc.core.ArgumentPreparedStatementSetter.doSetValue(ArgumentPreparedStatementSetter.java:69)ntat org.springframework.jdbc.core.ArgumentPreparedStatementSetter.setValues(ArgumentPreparedStatementSetter.java:50)ntat org.springframework.jdbc.core.JdbcTemplate.lambda$update$2(JdbcTemplate.java:963)ntat org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:651)ntat org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:960)ntat org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:1015)ntat org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:1025)

And also the query itself (please understand the sql dialect mistakes and everything which may look odd, because the code comes from a commercial project):

UPDATE <TABLE_NAME> SET revision=revision + 1, column2 = ?, column3 = ?, ... WHERE id = ? , [null, , , ...]

I can also provide you a version in which everything worked perfectly fine, before upgrading the sqlite library -> 3.32.3.2

Environment (please complete the following information):

  • OS: macOS Ventura
  • CPU architecture: M1 Pro (arm64)
  • sqlite-jdbc version 3.41.2.2 & 3.42.0.0
@dbelob
Copy link

dbelob commented Aug 23, 2023

Describe the bug
NullPointerException for org.sqlite.jdbc3.JDBC3PreparedStatement.getParameterType when no parameter has been set yet.

To Reproduce
Examples to reproduce error: see sqlite-jdbc-first-null-error repository.

There are two classes:

  1. JdbcTemplateTest contains tests when used Spring JdbcTemplate methods
  2. PreparedStatementTest contains tests when used JDBC PreparedStatement methods

In both cases updateWithFirstNull test fails with NullPointerException since SQLite JDBC 3.41.2.2

Error reproduction for Spring JdbcTemplate (see JdbcTemplateTest.updateWithFirstNull method):

    @Test
    void updateWithFirstNull() {
        // NullPointerException since SQLite JDBC 3.41.2.2
        int count = jdbcTemplate.update("update test_table set first_field = ?, second_field = ?", null, "text 2");

        assertEquals(1, count);
    }

Error reproduction for JDBC PreparedStatement (see PreparedStatementTest.updateWithFirstNull method):

    @Test
    void updateWithFirstNull() throws SQLException {
        stat.executeUpdate("create table if not exists test_table(first_field integer, second_field text)");
        stat.executeUpdate("insert into test_table (first_field, second_field) values (1, 'text 1')");

        try (PreparedStatement ps = conn.prepareStatement("update test_table set first_field = ?, second_field = ?")) {
            // NullPointerException since SQLite JDBC 3.41.2.2
            assertThrows(SQLException.class, () -> ps.getParameterMetaData().getParameterType(1));
        }
    }

Expected behavior
SQLException should be thrown instead NullPointerException.

Environment (please complete the following information):

  • OS: all
  • CPU architecture: x86_64, arm64
  • sqlite-jdbc version 3.41.2.2, 3.42.0.0 (since 3.41.2.2)

Additional context
Error appeared after issue #882 and fixed by issue #911 (PR #912).
Fix should be included in the next release after 3.42.0.0 (according to the commits).

Don't need to do anything, it's a duplicate of issue #911

@dbelob
Copy link

dbelob commented Aug 23, 2023

@razvanmihaescu please check that the next version will fix your issue:

  1. Clone SQLite JDBC repository: git clone https://github.com/xerial/sqlite-jdbc.git
  2. Change directory: cd sqlite-jdbc
  3. Build and install current unreleased version to local Maven repository: mvn clean install
  4. Change version of org.xerial:sqlite-jdbc artifact to 3.42.0.1-SNAPSHOT in pom.xml of your application
  5. Run your application: the error should disappear

@gotson
Copy link
Collaborator

gotson commented Aug 23, 2023

@razvanmihaescu please check that the next version will fix your issue:

  1. Clone SQLite JDBC repository: git clone https://github.com/xerial/sqlite-jdbc.git
  2. Change directory: cd sqlite-jdbc
  3. Build and install current unreleased version to local Maven repository: mvn clean install
  4. Change version of org.xerial:sqlite-jdbc artifact to 3.42.0.1-SNAPSHOT in pom.xml of your application
  5. Run your application: the error should disappear

Or use the snapshot from maven snapshots.

@gotson
Copy link
Collaborator

gotson commented Aug 25, 2023

@razvanmihaescu please try the latest release 3.42.0.1

@gotson gotson added waiting for feedback Waiting for a feedback from the issue creator and removed triage labels Aug 25, 2023
@gotson gotson closed this as completed Oct 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting for feedback Waiting for a feedback from the issue creator
Projects
None yet
Development

No branches or pull requests

3 participants