Drop VirtualMap.getForModify() API
Opened this issue · 0 comments
artemananiev commented
VirtualMap
provides java.util.Map like API, but besides that - a weird method getForModify()
. This method is similar to get()
: it returns a value from the map, or null if the corresponding key is not in the map. The key difference between get()
and getForModify()
is that the value returned by the latter can be changed later, and these changes will be reflected in the map.
There are a few concerns about it:
- This approach opens a possibility for un-intentional changes. It may not be clear that changing an object without an explicit
put()
to the map may still change the value in the map - All recent virtual maps used in Hedera services code are used to store immutable objects: HAPI-generated Java records. There is no way to mutate them. Typical pattern is
getForModify()
, followed by object copy, then the copy is modified, andput()
back to the map explicitly - If virtual maps are changed to work with
Bytes
for both keys and values,getForModify()
will still be impossible to implement, sinceBytes
objects are immutable, too
This ticket is to get rid of getForModify()
in VirtualMap
and all services code. This is already a part of #16699, but it can be done as a separate fix to reduce the scope of 16699 (which is huge even without this part).