Subscription query initialResult throws NullPointerException when query handler returns null when using QueryGateway
See original GitHub issueExpecting subscriptionQuery initialResult empty Mono when query handler returns null. With Axon 3.3.6 we’re getting the following:
Caused by: java.lang.NullPointerException: The mapper returned a null value.
at java.base/java.util.Objects.requireNonNull(Objects.java:246)
at reactor.core.publisher.FluxMap$MapSubscriber.onNext(FluxMap.java:100)
at reactor.core.publisher.MonoCreate$DefaultMonoSink.success(MonoCreate.java:146)
at org.axonframework.queryhandling.MonoSinkWrapper.success(MonoSinkWrapper.java:48)
at java.base/java.util.concurrent.CompletableFuture.uniAcceptNow(CompletableFuture.java:753)
at java.base/java.util.concurrent.CompletableFuture.uniAcceptStage(CompletableFuture.java:731)
at java.base/java.util.concurrent.CompletableFuture.thenAccept(CompletableFuture.java:2108)
at org.axonframework.queryhandling.SimpleQueryBus.lambda$subscriptionQuery$7(SimpleQueryBus.java:246)
at org.axonframework.queryhandling.MonoWrapper.lambda$create$0(MonoWrapper.java:62)
at reactor.core.publisher.MonoCreate.subscribe(MonoCreate.java:54)
at reactor.core.publisher.MonoMap.subscribe(MonoMap.java:55)
at reactor.core.publisher.Mono.subscribe(Mono.java:3088)
at reactor.core.publisher.Mono.subscribeWith(Mono.java:3196)
at reactor.core.publisher.Mono.toFuture(Mono.java:3513)
... 31 more
Test case to reproduce with Spring Boot 2.0.5:
import org.axonframework.queryhandling.QueryGateway;
import org.axonframework.queryhandling.QueryHandler;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.stereotype.Component;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.concurrent.ExecutionException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
@RunWith(SpringRunner.class)
@SpringBootTest
@SpringBootApplication
public class AxonApplicationTests {
@Autowired
QueryGateway queryGateway;
@Test
public void testNullReturnFromQueryHandler() throws ExecutionException, InterruptedException {
String notFound = queryGateway.subscriptionQuery(new MyQuery("not found"), String.class, String.class)
.initialResult()
.toFuture().get();
assertNull(notFound);
}
@Test
public void testNonNullReturnFromQueryHandler() throws ExecutionException, InterruptedException {
String found = queryGateway.subscriptionQuery(new MyQuery("found"), String.class, String.class)
.initialResult()
.toFuture().get();
assertEquals(found, "found");
}
}
class MyQuery {
String param;
public MyQuery(String param) {
this.param = param;
}
}
@Component
class MyQueryHandlerProjection {
@QueryHandler
public String handle(MyQuery query) {
return "found".equals(query.param) ? "found" : null;
}
}
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Subscription Query Initial Result Does Not Trigger Query ...
When I invoke the initialResults() method of the SubscriptionQueryResult my query handler is not getting triggered, and subsequently I just get a null...
Read more >How to Handle NullpointerException when Query throws ...
You could use a java.lang.Double instead of a primitive double , and then programatically check for null : String Query="SELECT SUM(tot) ...
Read more >queryGateway on null - Google Groups
I use the queryGateway to get a value from a map. private val accounts: MutableMap<String, Int> = mutableMapOf()@QueryHandler ...
Read more >Dispatching Queries in Axon Framework - Baeldung
When we submit a query to Axon, the framework will issue that query to all registered query handlers capable of answering our query....
Read more >NullPointer exception on field that is retrieved on the query
isBlank() works for determining if the field is empty. If I negate this method result, though, the null pointer error persists. String.isBlank( ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This issue has been resolved in commit 7be1c5c, hence closing. Thanks for notifying us of this @leowentzel!
Upgraded to 3.4 and it works! Well done!