A basic postgre sql query fails for me

146 views
Skip to first unread message

dharma teja

unread,
Oct 17, 2017, 10:08:58 AM10/17/17
to vert.x
Hi All,

I have SQLconnection established with the postgreSQL db but when I initiate a query i receive an exception. The backtrace of which is as follow:

java.lang.NullPointerException
        at postgre.client.PostgreClient.lambda$null$0(PostgreClient.java:41)
        at io.vertx.ext.asyncsql.impl.AsyncSQLConnectionImpl.lambda$handleAsyncQueryResultToResultSet$12(AsyncSQLConnectionImpl.java:276)
        at io.vertx.core.impl.FutureImpl.tryComplete(FutureImpl.java:126)
        at io.vertx.core.impl.FutureImpl.complete(FutureImpl.java:88)
        at io.vertx.ext.asyncsql.impl.ScalaUtils$1.apply(ScalaUtils.java:51)
        at io.vertx.ext.asyncsql.impl.ScalaUtils$1.apply(ScalaUtils.java:47)
        at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:60)
        at io.vertx.ext.asyncsql.impl.VertxEventLoopExecutionContext.lambda$execute$0(VertxEventLoopExecutionContext.java:59)
        at io.vertx.core.impl.ContextImpl.lambda$wrapTask$2(ContextImpl.java:337)
        at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163)
        at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:403)
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:445)
        at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:858)
        at java.lang.Thread.run(Unknown Source)

The complete piece of code that creates a shared pool for postgreSQL client, gets the connection and initiates a simple query is as follows:

JsonObject postgreSQLConfig = new JsonObject().put("host", "localhost").put("port", 5432)
.put("username", "username").put("password", "password").put("database", "database");

SQLClient postgreClient = PostgreSQLClient.createShared(vertx, postgreSQLConfig, "postgreSQLPool");

postgreClient.getConnection(res -> {
if (res.failed()) {
System.out.println("Postgre Client connection failed " + res.cause());
return;
}
connectionSQL = res.result();
connectionSQL.query("SELECT * FROM public.users", resQuery -> {
if (resQuery.failed()) {
resQuery.cause().printStackTrace(); // FAILS!!
} else {
System.out.println("Query result " + resQuery.result().getOutput().toString());
}
});

I didn't find any direct reference to this particular issue with vertx on google, maybe some of you have come across this.
Open for suggestions and tries.

Thank you very much in advance.

Thomas SEGISMONT

unread,
Oct 17, 2017, 11:07:05 AM10/17/17
to ve...@googlegroups.com
I can't see anything wrong at first glance. Could you put together a small reproducer on GitHub? With a Docker command for Postgres setup please. Thanks!

--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/d48c28bc-147b-4582-a0af-4f0afe549ac6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

JavaDave

unread,
Oct 18, 2017, 10:34:13 AM10/18/17
to vert.x
Are you sure that resQuery.cause() itself doesn't return null?

dharma teja

unread,
Oct 20, 2017, 3:30:14 AM10/20/17
to ve...@googlegroups.com
I am new to Vertx, this is my beginners mistake.

 The null exception was causing by "resQuery.result().getOutput()" so 'resQuery.failed()' being FALSE is true. The cool thing is that it seems the exception is handled by this sql client library and recalls my handler 'resQuery' with 'resQuery.failed()' set to TRUE, that is when I print the stack trace for the resQuery.cause(), I see that in the trace it actually points to the line in my code where there is a null pointer access.

--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.

For more options, visit https://groups.google.com/d/optout.



--
Best regards,
Dharma

Alexander Lehmann

unread,
Oct 20, 2017, 7:22:23 AM10/20/17
to vert.x
This behaviour is quite cool, though I believe it violates the expectation what an AsyncResult is (that it is either successful or failed), so I would think that the library should report a NPE in the handler as unexpected exception.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.



--
Best regards,
Dharma

Reply all
Reply to author
Forward
0 new messages