Initializing asMapView in AbstractMultiValuedMap

Kaan Berk Yaman <[email protected]> Fri, 13 Sep 2024 16:09:10 +0200
Newsgroups gmane.comp.jakarta.commons.user
Message-ID <[email protected]>
Hello,

I was doing some testing with a record that has an 
ArrayListValuedHashMap as one of its components. I use AssertJ to do a 
deep, recursive, field-to-field comparison of the record. All of the 
members of the list-valued map have respective `equals` and `hashCode` 
implementations. I have, however, noticed that, when I have two equal 
LV-maps, if I call `asMap` on one, AssertJ reports that the two 
LV-valued maps are not equal, due to the `asMapView` field, which is 
`null` for the other LV-map; this field seems to be initialized upon the 
first call of `asMap`. The assertion runs through if I call `asMap` on 
the other map, too.
It seems like `asMapView` is kept updated as long as `asMap` is called 
at least once. Is this expected behaviour? If yes, I feel like this 
should be documented somewhere; the Javadoc comment of `asMap` has no 
mention of `asMapView` and how this field is used for caching.

Thanks in advance.

Kind regards
Kaan