question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Subscription query initialResult throws NullPointerException when query handler returns null when using QueryGateway

See original GitHub issue

Expecting 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:closed
  • Created 5 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
smcvbcommented, Oct 17, 2018

This issue has been resolved in commit 7be1c5c, hence closing. Thanks for notifying us of this @leowentzel!

0reactions
leowentzelcommented, Oct 25, 2018

Upgraded to 3.4 and it works! Well done!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found