Yes, exactly, it returns null. The Java contract is to return the existing value or the new (computed value) instead.
Dne 11. 2. 2022 16:24 napsal uživatel Reuven Lax <[email protected]>:
I'm not sure I understand what you mean. Do you mean it always returns null? Since computeIfAbsent doesn't modify the value unless it is not present, I'm not sure what the "old value" means, unless you mean that it returns null.On Fri, Feb 11, 2022 at 4:54 AM Jan Lukavský <[email protected]> wrote:Hi,
I just found another weirdness in the MapState API - method
computeIfAbsent returns the _old_ value associated with the key. That is
inconsistent with Java API and frankly with what users should expect
when using this method. The semantics should be "retrieve current value,
if not present associate the key with this one and return me the current
value". Is this behavior intentional? What is the motivation? In
combination with the previous thread [1] that states, that the value is
not updated until read() of the state returned from computeIfAbsent is
called this seems to force users to either fetch the state twice or do
various workarounds.
Jan
[1] https://lists.apache.org/thread/mp979twlgm76gjg014f5r0k2p0nlcj2q
