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

Setting null value on PreparedStatement::setClob produces NullPointerException #712

Closed
lukaseder opened this issue Oct 11, 2022 · 2 comments

Comments

@lukaseder
Copy link

Try this code:

try (PreparedStatement s = connection.prepareStatement(
    """
    SELECT cast(? as blob sub_type text) FROM rdb$database
    """
)) {
    s.setClob(1, (Clob) null);
    try (ResultSet rs = s.executeQuery()) {
        while (rs.next())
            System.out.println(rs.getString(1));
    }
}

It produces:

Exception in thread "main" java.lang.NullPointerException: Cannot invoke "java.sql.Clob.getCharacterStream()" because "clob" is null
	at org.firebirdsql.jdbc.AbstractPreparedStatement.setClob(AbstractPreparedStatement.java:723)
	at org.jooq.testscripts.JDBC.main(JDBC.java:71)

This works:

try (PreparedStatement s = connection.prepareStatement(
    """
    SELECT cast(? as blob sub_type text) FROM rdb$database
    """
)) {
    s.setNull(1, Types.CLOB);
    try (ResultSet rs = s.executeQuery()) {
        while (rs.next())
            System.out.println(rs.getString(1));
    }
}

And so does this:

try (PreparedStatement s = connection.prepareStatement(
    """
    SELECT cast(? as blob sub_type text) FROM rdb$database
    """
)) {
    s.setString(1, null);
    try (ResultSet rs = s.executeQuery()) {
        while (rs.next())
            System.out.println(rs.getString(1));
    }
}

Other drivers support null values on the setClob() (or setBlob()) methods. I don't think the behaviour is ambiguous. In fact, I think it's inconsistent with ResultSet behaviour:

try (PreparedStatement s = connection.prepareStatement(
    """
    SELECT cast(? as blob sub_type text) FROM rdb$database
    """
)) {
    s.setString(1, null);
    try (ResultSet rs = s.executeQuery()) {
        while (rs.next())
            System.out.println(rs.getClob(1));
    }
}

When fetching the CLOB value, the ResultSet returns a null value, so it should be possible to bind it as well.

@mrotteveel
Copy link
Member

Yes, this is indeed a bug (violates section 13.2.2.4 of JDBC 4.3).

@mrotteveel
Copy link
Member

Fixed for Jaybird 4.0.7 and Jaybird 5. Thanks for reporting!

Jaybird 4.0.7 will probably be released around the end of October.

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