Form.setItemDataSource and TwinColSelect called 5 times by Drawer

I have a simple subclass of Form that uses a bean item and sets it via:

super.setItemDataSource(newDataSource, _orderedProperties);

One of my properties (memberGroupsUpdateIds) returns a Set to be used in TwinColSelect (it’s actually a HashSet of UUIDs).

I noted that my getMemberGroupsUpdateIds() bean method is first called when I call the setItemDataSource as above. That seems reasonable.

But then it appears it’s called 5 more times. It seems to occur when Form.paintContent() is called, that eventually calls TwinColSelect.paint()/paintContent() to be called which then causesTwinColSelect.getValue() to be called 5 times, each time resulting in a call to my getMemberGroupsUpdateIds(), so I create the same HashSet a total of 6 times when I’d figure this would only occur once.

It seems to be related to the TwinColSelect…

The first time comes from:
AbstractSelect.paintContent() line: selectedKeys = new String[((Set) getValue()).size()]
;

Second time comes from:
AbstractSelect.isSelected() line: return ((Set) getValue()).contains(itemId);

Third time is the same isSelected (no doubt with a different itemid – I believe I have two items, implying that this could be even worse if my select box has more choices)

Fourth time seems to be:
AbstractSelect.isEmpty() line: Object value = getValue();

Fifth time seems to be:
AbstractField.isEmpty() line: return (getValue() == null);

Clearly the getValue() is called many times, so I can help this by caching the HashSet created so it can be returned each time. But this might help others who have getters methods in their BeanItems that do any calculations or other “bigger operations” other than returning a simple field when used in a Select.