jdbi: NPE when using @Define on null values

I’m currently using null values (albeit without success) while trying to implement conditional sql statements

@SqlQuery("select * from test_table <if(created)> where created >= #created <endif>")
List<TestItem> getTestItems(@Define OffsetDateTime created);

If I pass a non-null OffsetDateTime value, no problems. However when I do, it results in an NPE at https://github.com/jdbi/jdbi/blob/2cb484e3b9357e77ba12de09655632a1270ecb49/core/src/main/java/org/jdbi/v3/core/statement/SqlStatements.java#L54

This is because the attributes (a ConcurrentHashMap instance) doesn’t accept null values.

Is this the expected behavior, if not happy to do a simple PR guarding against trying to put null values into the ConcurrentHashMap, which if I’m not mistaken will fix my issue.

If this is the expected behavior, what’s the best way to go about using this kind of conditional SQL statements?

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 22 (13 by maintainers)

Most upvoted comments

It seems wise to me to not conflate “null because key not found” and “null because null stored”. They wanted to keep them separate in ConcurrentHashMap too but were stuck with interface compatibility.