[v7] .isEmpty() method on a ListSelect == odd behaviour

I’m having a hard time trying to #1 populate a ListSelect with some items, composed of their respective id plus caption, #2 determining if the ListSelect is empty or not.

The truth is that I already accomplished #2 by my own methods, but I’m feeling angry because the .isEmpty() method doesn’t work on it as I would expect. No matter what attempt, it always return true for me - while the ListSelect is obviously populated with items, as I see it with my own eyes on the screen.

When attempting a debugging session, I see that my ListSelect has an underlying IndexedContainer datasource (named “items”) and, then, inside this, and underlying Hashtable (again with the name “items” with, in my opinion, is a poor choice which only adds more confusion). This Hashtable has some entries, which correspond to the effective visible “items” on the ListSelect. The ¿problem? is that their keys don’t point to any value. I suspect is this what causes the .isEmpty() method to return true (I remember like reading some explanation soomewhere in the docs). Or maybe it is because the propertyIds ArrayList of the items IndexedContainer is empty. I don’t know; I haven’t done further debugging. Anyway, my ListSelect is populated via the usual recipe of Item item = ListSelect.addItem(id), and then I add a caption for that “item” via ListSelect.setItemCaption(id,“Custom Caption”). So I’d expect that this would just “arrange” the internals of ListSelect in some congruent way which would cause .isEmpty() not to be empty.

Instead, I cannot rely on this method and have to do a ListSelect.getItemIds().size(). It returns the number of elements I see with my bare eye on the screen.

Another thing that confuses me a lot if that I have two .addItem() overloads for this kind of control, one returning the Item itself and another returning the Item id, which is what I’m used to. I was using the first one, getting the Item instead of the ItemId, and I spent some time going crazy until I realized this.