Skip to content

Commit dfec159

Browse files
authored
PgClient: NPE when inserting null param with default param extractor (#1486)
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 <tsegismont@gmail.com>
1 parent 94b4ae1 commit dfec159

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

vertx-pg-client/src/main/java/io/vertx/pgclient/impl/codec/DataType.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,10 @@ private static class DefaultParamExtractor<T> implements ParamExtractor<T> {
237237
@Override
238238
public T get(TupleInternal tuple, int idx) {
239239
Object value = tuple.getValue(idx);
240-
if (value != null && encodingType.isAssignableFrom(value.getClass())) {
240+
if (value == null) {
241+
return null;
242+
}
243+
if (encodingType.isAssignableFrom(value.getClass())) {
241244
return encodingType.cast(value);
242245
}
243246
throw FAILURE;

vertx-pg-client/src/test/java/io/vertx/pgclient/data/PreparedStatementParamCoercionTest.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package io.vertx.pgclient.data;
22

3-
import io.vertx.pgclient.PgConnection;
4-
import io.vertx.sqlclient.Tuple;
53
import io.vertx.ext.unit.Async;
64
import io.vertx.ext.unit.TestContext;
5+
import io.vertx.pgclient.PgConnection;
6+
import io.vertx.sqlclient.Tuple;
77
import io.vertx.sqlclient.data.Numeric;
88
import org.junit.Test;
99

@@ -68,4 +68,16 @@ public void testCoercionError(TestContext ctx) {
6868
}));
6969
}));
7070
}
71+
72+
@Test
73+
public void testNoCoercionErrorWithNull(TestContext ctx) {
74+
PgConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> {
75+
conn.prepare("SELECT $1::POINT").onComplete(ctx.asyncAssertSuccess(pq -> {
76+
pq
77+
.query()
78+
.execute(Tuple.of(null))
79+
.onComplete(ctx.asyncAssertSuccess());
80+
}));
81+
}));
82+
}
7183
}

0 commit comments

Comments
 (0)