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

@SqlBatch doesn't like NULL parameter #1770

Closed
ayethu opened this issue Oct 5, 2020 · 1 comment
Closed

@SqlBatch doesn't like NULL parameter #1770

ayethu opened this issue Oct 5, 2020 · 1 comment

Comments

@ayethu
Copy link

ayethu commented Oct 5, 2020

Environment

  • jdbi 3.14.4
  • JDK 1.8.0_45
  • OSX Catalina 10.15.6

Description:
If you have multiple bind parameters for a @SqlBatch method, and one of the non-iterable parameter is NULL, the following error is thrown:

java.lang.NullPointerException
        at org.jdbi.v3.core.internal.IterableLike.isIterable(IterableLike.java:48)
        at org.jdbi.v3.sqlobject.statement.internal.SqlBatchHandler.zipArgs(SqlBatchHandler.java:269)
        at org.jdbi.v3.sqlobject.statement.internal.SqlBatchHandler.invoke(SqlBatchHandler.java:174)
        at org.jdbi.v3.sqlobject.internal.SqlObjectInitData$1.lambda$invoke$0(SqlObjectInitData.java:125)
        at org.jdbi.v3.sqlobject.internal.SqlObjectInitData$1$$Lambda$614/447234532.call(Unknown Source)
        at org.jdbi.v3.core.internal.Invocations.invokeWith(Invocations.java:44)
        at org.jdbi.v3.core.internal.Invocations.invokeWith(Invocations.java:26)
        at org.jdbi.v3.core.LazyHandleSupplier.lambda$invokeInContext$1(LazyHandleSupplier.java:77)
        at org.jdbi.v3.core.LazyHandleSupplier$$Lambda$615/1028348585.call(Unknown Source)
        at org.jdbi.v3.core.internal.Invocations.invokeWith(Invocations.java:44)
        at org.jdbi.v3.core.internal.Invocations.invokeWith(Invocations.java:26)
        at org.jdbi.v3.core.LazyHandleSupplier.invokeInContext(LazyHandleSupplier.java:76)
        at org.jdbi.v3.sqlobject.internal.SqlObjectInitData$1.call(SqlObjectInitData.java:131)
        at org.jdbi.v3.sqlobject.internal.SqlObjectInitData$1.invoke(SqlObjectInitData.java:125)
        at org.jdbi.v3.sqlobject.SqlObjectFactory.lambda$attach$2(SqlObjectFactory.java:110)

Example, durationMins is null :

    @SqlBatch
    @GetGeneratedKeys
    long[] saveBatch(@Bind("user_id") Long userId,
                    @Bind("contact_id") Long contactId,
                    @Bind("scheduled_on") List<LocalDateTime> scheduledOn,
                    @Bind("duration_mins") Integer durationMinutes,
                    @Bind("state_id") Integer stateId,
                    @Bind("duologue_type_id") Integer typeId,
                    @Bind("title") List<String> title);

This can probably be handled with a null check for the IterableLike.isIterable() method call:

public static boolean isIterable(Object maybeIterable) {
        return maybeIterable instanceof Iterator<?>
            || maybeIterable instanceof Iterable<?>
            || maybeIterable.getClass().isArray();
    }

The maybeIterable.getClass().isArray() line is the one that's throwing NPE.

@stevenschlansker
Copy link
Member

Thanks for reporting this, I think this is the same as #1761 which is fixed in 3.15.0 or 3.14.5

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

No branches or pull requests

2 participants