Navigation Menu

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

Statement.Builder#bind("some-param").to((Value) null) causes NullPointerException #1679

Closed
olavloite opened this issue Feb 11, 2022 · 0 comments · Fixed by #1680 or #1675
Closed

Statement.Builder#bind("some-param").to((Value) null) causes NullPointerException #1679

olavloite opened this issue Feb 11, 2022 · 0 comments · Fixed by #1680 or #1675
Assignees
Labels
api: spanner Issues related to the googleapis/java-spanner API. priority: p3 Desirable enhancement or fix. May not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@olavloite
Copy link
Collaborator

Setting a statement parameter to an untyped null value will cause a NullPointerException. Example:

Statement.newBuilder("INSERT INTO T (K, V) VALUES (@p1, @p2)")
    .bind("p1")
    .to("k1")
    .bind("p2")
    .to((Value) null)
    .build()))

Untyped null values are often used in ORMs and is commonly used in the JDBC driver. This will also be necessary for PostgreSQL connections, as the PostgreSQL JDBC driver allows applications to supply untyped null parameter values.

@olavloite olavloite added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. priority: p3 Desirable enhancement or fix. May not be included in next release. labels Feb 11, 2022
@olavloite olavloite self-assigned this Feb 11, 2022
@product-auto-label product-auto-label bot added the api: spanner Issues related to the googleapis/java-spanner API. label Feb 11, 2022
olavloite added a commit that referenced this issue Feb 11, 2022
Adding an untyped null value as a parameter to a statement was not
possible, as:
1. The parameter collection would allow a null value to be added, but
   when the statement was built, it would throw a NullPointerException
   because it used an ImmutableMap internally, which does not support
   null values.
2. The translation from a hand-written Statement instance to a proto
   Statement instance would fail, as it did not take into account that
   the parameter could be null.

Fixes #1679
olavloite added a commit that referenced this issue Feb 15, 2022
Adding an untyped null value as a parameter to a statement was not
possible, as:
1. The parameter collection would allow a null value to be added, but
   when the statement was built, it would throw a NullPointerException
   because it used an ImmutableMap internally, which does not support
   null values.
2. The translation from a hand-written Statement instance to a proto
   Statement instance would fail, as it did not take into account that
   the parameter could be null.

Fixes #1679
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: spanner Issues related to the googleapis/java-spanner API. priority: p3 Desirable enhancement or fix. May not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
1 participant