centiservice / mats3

Mats3: Message-based Asynchronous Transactional Staged Stateless Services
https://mats3.io/
Other
63 stars 7 forks source link

Null incoming state: From an initiate, perform a request with replyTo(multistage, null) leads to problems #64

Closed stolsvik closed 2 years ago

stolsvik commented 2 years ago

Reported by @staale.

Original title: "Stage crash: From an initiate, send a request with replyTo(MatsClassMapping, null), i.e. null incoming state"

Turns out the problem is "deeper", in that this also happens for an ordinary MultiStage - it has nothing to do with @MatsClassMapping, only there it breaks immediately upon initial stage, as the incoming state is null, and since the state object for @MatsClassMapping is "this", setting of fields (and later, invoking of methods) doesn't work with null!

stolsvik commented 2 years ago

From the JavaDoc of the test class for research and fix:

If an initiation request is performed to some EndpointX, with init.replyTo(EndpointA, null), i.e. the replyStatebeing null, EndpointA was actually invoked with null state. This on first blush seems intuitive, but it screws over what EndpointA expects: It has declared some state class S, and expects to be able to set variables on it etc - it makes no sense that it suddenly is null. Also, Mats internals (specifically MatsTraceFieldImpl) also expects it to be non-null if the Endpoint is multi-stage, as it should serialize it onto the stack upon REQUEST or NEXT. Therefore, a state object cannot ever be null, and in the specific situation with replyState = null, this must instead create a new empty state object.