diff --git a/vertx-pg-client/src/main/java/io/vertx/pgclient/impl/codec/DataType.java b/vertx-pg-client/src/main/java/io/vertx/pgclient/impl/codec/DataType.java index e81c014de..707d093ef 100644 --- a/vertx-pg-client/src/main/java/io/vertx/pgclient/impl/codec/DataType.java +++ b/vertx-pg-client/src/main/java/io/vertx/pgclient/impl/codec/DataType.java @@ -237,7 +237,10 @@ private static class DefaultParamExtractor implements ParamExtractor { @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; diff --git a/vertx-pg-client/src/test/java/io/vertx/pgclient/data/PreparedStatementParamCoercionTest.java b/vertx-pg-client/src/test/java/io/vertx/pgclient/data/PreparedStatementParamCoercionTest.java index bc2db2152..0288af029 100644 --- a/vertx-pg-client/src/test/java/io/vertx/pgclient/data/PreparedStatementParamCoercionTest.java +++ b/vertx-pg-client/src/test/java/io/vertx/pgclient/data/PreparedStatementParamCoercionTest.java @@ -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; @@ -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()); + })); + })); + } }