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

Batch::executeAsync throws NullPointerException when executed with R2DBC driver #15331

Closed
lukaseder opened this issue Jul 3, 2023 · 4 comments

Comments

@lukaseder
Copy link
Member

We don't currently implement Batch.executeAsync() based on R2DBC driver backed Configuration yet. Trying to call this method results in a NullPointerException. We should throw a more meaningful exception in that case.


See also:

@lukaseder
Copy link
Member Author

Other methods already throw an appropriate exception, e.g. this test passes:

public void testR2DBCCallBlockingFetchAsync() throws Exception {
    assumeR2DBCAvailable();

    bindAndInlineWithDSLContexts(ctx -> {
        ctx.configuration().set(new NoConnectionProvider());

        assertThrows(CompletionException.class,
            () -> ctx.selectOne().fetchAsync().toCompletableFuture().join(),
            e -> assertTrue(e.getCause().getMessage(), e.getCause().getMessage().startsWith("Attempt to execute a blocking method"))
        );
    }, r2dbc());
}

@lukaseder
Copy link
Member Author

But indeed, the batch call assertion fails:

java.lang.AssertionError: Bad exception type. Expected: org.jooq.exception.DetachedException. Got: java.util.concurrent.CompletionException
	at org.jooq.test.util.BaseTest.assertThrowsIf(BaseTest.java:420)
	at org.jooq.test.util.BaseTest.assertThrows(BaseTest.java:387)
	at org.jooq.test.all.testcases.R2DBCTests.lambda$36(R2DBCTests.java:720)
	at org.jooq.test.jOOQAbstractTest.withDSLContext(jOOQAbstractTest.java:2425)
	at org.jooq.test.jOOQAbstractTest.bindAndInlineWithDSLContexts(jOOQAbstractTest.java:2418)
	at org.jooq.test.BaseTest.bindAndInlineWithDSLContexts(BaseTest.java:2129)
	at org.jooq.test.all.testcases.R2DBCTests.testR2DBCCallBlockingBatchExecuteAsync(R2DBCTests.java:716)
	at org.jooq.test.jOOQAbstractTest.testR2DBCCallBlockingBatchExecuteAsync(jOOQAbstractTest.java:3042)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
	at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:61)
	at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:61)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
	at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
	at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:93)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:40)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:529)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:756)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:452)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:210)
Caused by: java.util.concurrent.CompletionException: java.lang.NullPointerException: Cannot invoke "java.sql.Connection.createStatement()" because "connection" is null
	at java.base/java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:315)
	at java.base/java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:320)
	at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1770)
	at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.exec(CompletableFuture.java:1760)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373)
	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182)
	at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655)
	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622)
	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165)
Caused by: java.lang.NullPointerException: Cannot invoke "java.sql.Connection.createStatement()" because "connection" is null
	at org.jooq_3.19.0-SNAPSHOT.POSTGRES.debug(Unknown Source)
	at org.jooq.impl.SettingsEnabledPreparedStatement.<init>(SettingsEnabledPreparedStatement.java:93)
	at org.jooq.impl.SettingsEnabledPreparedStatement.<init>(SettingsEnabledPreparedStatement.java:97)
	at org.jooq.impl.BatchMultiple.execute(BatchMultiple.java:114)
	at org.jooq.impl.BatchMultiple.lambda$1(BatchMultiple.java:93)

@lukaseder lukaseder added this to To do in 3.15 Reactive query execution via automation Jul 10, 2023
@lukaseder lukaseder removed this from To do in 3.19 Other improvements Jul 10, 2023
@lukaseder
Copy link
Member Author

The problem isn't really related to R2BDC. The main reason is that we try to fetch an ExecuteContext::connection, which can be null, and don't check for null ness. I.e. we don't throw the usual DetachedException that we should.

3.15 Reactive query execution automation moved this from To do to Done Jul 10, 2023
lukaseder added a commit that referenced this issue Jul 11, 2023
lukaseder added a commit that referenced this issue Jul 11, 2023
lukaseder added a commit that referenced this issue Jul 11, 2023
lukaseder added a commit that referenced this issue Jul 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

1 participant