When is ValueEntity's currentState updated?

Hi,
I write a simple value entity to create new customer and return it in toString format.
I use thenReply(currentState().toString()) after effects().updateState(), but it returns me an error that the currentState is null when calling toString().
So I wanna know when the current state will be updated in a value entity?

@Slf4j
@TypeId("customer")
@Id("id")
@RequestMapping("/customer/{id}")
@Acl(allow = @Acl.Matcher(principal = Acl.Principal.ALL))
public class CustomerEntity extends ValueEntity<CustomerEntity.Customer> {
  @PostMapping()
  public Effect<String> create(@PathVariable String id) {
    return effects().updateState(new Customer(id)).thenReply(currentState().toString());
  }

  public record Customer(String id) {}
}

error:

ERROR c.example.reproduce.CustomerEntity - Terminating entity [1233] due to unexpected failure for command [Create]
kalix.javasdk.impl.EntityExceptions$EntityException: Unexpected failure: java.lang.reflect.InvocationTargetException
        at kalix.javasdk.impl.EntityExceptions$EntityException$.apply(EntityExceptions.scala:50)
        at kalix.javasdk.impl.valueentity.ValueEntitiesImpl.liftedTree1$1(ValueEntitiesImpl.scala:180)
        at kalix.javasdk.impl.valueentity.ValueEntitiesImpl.$anonfun$runEntity$3(ValueEntitiesImpl.scala:173)
        at akka.stream.impl.fusing.Map$$anon$1.onPush(Ops.scala:54)
        at akka.stream.impl.fusing.GraphInterpreter.processPush(GraphInterpreter.scala:542)
        at akka.stream.impl.fusing.GraphInterpreter.execute(GraphInterpreter.scala:423)
        at akka.stream.impl.fusing.GraphInterpreterShell.runBatch(ActorGraphInterpreter.scala:650)
        at akka.stream.impl.fusing.GraphInterpreterShell$AsyncInput.execute(ActorGraphInterpreter.scala:521)
        at akka.stream.impl.fusing.GraphInterpreterShell.processEvent(ActorGraphInterpreter.scala:625)
        at akka.stream.impl.fusing.ActorGraphInterpreter.akka$stream$impl$fusing$ActorGraphInterpreter$$processEvent(ActorGraphInterpreter.scala:800)
        at akka.stream.impl.fusing.ActorGraphInterpreter.akka$stream$impl$fusing$ActorGraphInterpreter$$shortCircuitBatch(ActorGraphInterpreter.scala:787)
        at akka.stream.impl.fusing.ActorGraphInterpreter$$anonfun$receive$1.applyOrElse(ActorGraphInterpreter.scala:819)
        at akka.actor.Actor.aroundReceive(Actor.scala:537)
        at akka.actor.Actor.aroundReceive$(Actor.scala:535)
        at akka.stream.impl.fusing.ActorGraphInterpreter.aroundReceive(ActorGraphInterpreter.scala:716)
        at akka.actor.ActorCell.receiveMessage(ActorCell.scala:579)
        at akka.actor.ActorCell.invoke(ActorCell.scala:547)
        at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:270)
        at akka.dispatch.Mailbox.run(Mailbox.scala:231)
        at akka.dispatch.Mailbox.exec(Mailbox.scala:243)
        at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:387)
        at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1312)
        at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1843)
        at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1808)
        at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:188)
Caused by: java.lang.reflect.InvocationTargetException: null
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:115)
        at java.base/java.lang.reflect.Method.invoke(Method.java:580)
        at kalix.javasdk.impl.MethodInvoker.invoke(CommandHandler.scala:78)
        at kalix.javasdk.impl.valueentity.ReflectiveValueEntityRouter.handleCommand(ReflectiveValueEntityRouter.scala:55)
        at kalix.javasdk.impl.valueentity.ValueEntityRouter._internalHandleCommand(ValueEntityRouter.scala:68)
        at kalix.javasdk.impl.valueentity.ValueEntitiesImpl.liftedTree1$1(ValueEntitiesImpl.scala:174)
        ... 23 common frames omitted
Caused by: java.lang.NullPointerException: Cannot invoke "com.example.reproduce.CustomerEntity$Customer.toString()" because the return value of "com.example.reproduce.CustomerEntity.currentState()" is null
        at com.example.reproduce.CustomerEntity.create(CustomerEntity.java:25)
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
        ... 28 common frames omitted

I think your expectation is correct and that you have found a bug, I have added it to our issue tracker over in github: Value entity state not readable from thenReply · Issue #1947 · lightbend/kalix-jvm-sdk · GitHub

Just to clarify, thenReply is called when create is called, not after/later, so what you do is exactly the same as:

public Effect<String> create(@PathVariable String id) {
    var state = currentState()
    return effects().updateState(new Customer(id)).thenReply(state.toString());
  }

But what we should improve in the SDK is to provide is a reply-overload that is invoked with the new state (so that it aligns with the event sourced entity:

   return effects().updateState(new Customer(id)).thenReply(newState -> newState.toString());

The method name thenReply sounds like a chain operation after the updateState, so I am expecting the currentState is the latest.
To aligns with the event sourced entity is absolutely correct.