Logging Interceptor throws exception while update aggregate workflow

I have implemented a CommandHandlerInterceptor extending the LoggingInterceptor.

The goal is to log the command and its payload. It works fine for all the create commands but fails with an exception like.

[UpdateBagCommand] executed successfully with a [null] return value


The execution of the command happens and the event is also generated.

It fails in the following method of the Logging Interceptor, pretty much the object returnValue comes as null.

public Object handle(UnitOfWork<? extends T> unitOfWork, InterceptorChain interceptorChain)
        throws Exception {
    T message = unitOfWork.getMessage();
    logger.info("Incoming message: [{}]", message.getPayloadType().getSimpleName());
    try {
        Object returnValue = interceptorChain.proceed();
        logger.info("[{}] executed successfully with a [{}] return value",
                returnValue == null ? "null" : returnValue.getClass().getSimpleName());
        return returnValue;
    } catch (Exception t) {
        logger.warn(format("[%s] execution failed:", message.getPayloadType().getSimpleName()), t);
        throw t;


I might not understand the problem here. The “exception” your are refering to is just a log message indicating that a null value was returned from a command. “null” is the only possible return value from a “void” method, so it simply means the command was successfully executed.


Hello Allard,

Yes, the command was successfully executed. What I noticed is that the framework expects you to return the aggregate id after the commandhandler execution. Something like

fun handler(command: UpdateProductCommand): UUID {

    var product: Aggregate<ProductAggregate> = productRepository.load(command.productId.toString())

    product.execute { aggregate -> aggregate.updateProduct(command) }

    return command.productId

If you do not return then it throws an exception.

Returning null from a command handler is a very normal thing to do. The logging interceptor does a nullcheck, so I don’t see where the exception is thrown.
Note that Kotlin treats nulls differently than Java. It may not like the fact that you’re returning null there…

Can you provide the entire stacktrace of the NPE or whichever exception you see?