Skip to content

Commit

Permalink
PgClient: NPE when inserting null param with default param extractor (#…
Browse files Browse the repository at this point in the history
…1486) (#1487)

See #1477

This is a regression introduced in #1464

When the value is null, the extractor throws a failure.
Then, in ErrorMessageFactory.buildWhenArgumentsTypeNotMatched, a NPE is thrown because the value of the class cannot be determined.

Signed-off-by: Thomas Segismont <[email protected]>
  • Loading branch information
tsegismont authored Jan 17, 2025
1 parent 5a6f7e6 commit 541ca43
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,10 @@ private static class DefaultParamExtractor<T> implements ParamExtractor<T> {
@Override
public T get(TupleInternal tuple, int idx) {
Object value = tuple.getValue(idx);
if (value != null && encodingType.isAssignableFrom(value.getClass())) {
if (value == null) {
return null;
}
if (encodingType.isAssignableFrom(value.getClass())) {
return encodingType.cast(value);
}
throw FAILURE;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package io.vertx.pgclient.data;

import io.vertx.pgclient.PgConnection;
import io.vertx.sqlclient.Tuple;
import io.vertx.ext.unit.Async;
import io.vertx.ext.unit.TestContext;
import io.vertx.pgclient.PgConnection;
import io.vertx.sqlclient.Tuple;
import io.vertx.sqlclient.data.Numeric;
import org.junit.Test;

Expand Down Expand Up @@ -64,4 +64,16 @@ public void testCoercionError(TestContext ctx) {
}));
}));
}

@Test
public void testNoCoercionErrorWithNull(TestContext ctx) {
PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> {
conn.prepare("SELECT $1::POINT").onComplete(ctx.asyncAssertSuccess(pq -> {
pq
.query()
.execute(Tuple.of(null))
.onComplete(ctx.asyncAssertSuccess());
}));
}));
}
}

0 comments on commit 541ca43

Please sign in to comment.