XWikiDocument#getXObjects and null elements

Hi everyone,

right now the XWikiDocument#getXObjects method is returning a List<BaseObject> that might contain null elements. This is clearly error-prone (not mentioning that this method was lacking documentation, which is definitely not helping), so we might want to improve this situation.

Of course we cannot just fix this method to only return lists without null elements: some extensions might rely on this behaviour to get the index of the base objects. Quite frankly I’d be interested if there’s developers who are relying on this, so please answer if you’re in this situation :slight_smile:

Now we already discussed a bit about that in the chat and so far 3 proposals emerged:

  1. to add a new method with a boolean parameter to allow filter out the null values
  2. to create a new method returning an iterator or a stream that is specifically filtering out the null values
  3. to deprecate this method and to create a new method returning a list without the null values

Note that in case of 3, we’d need to find a good name for the new method which won’t be easy. So far, 2 sounds like the easiest solution for the short term, but I don’t know where we want to go on the long term.

Also note that here I’m using singular to talk about this method, but in reality there’s two methods getXObjects one using a DocumentReference and another using an EntityReference.