There are two ways in which a message with type="definition" can be added to an array:
The message gets added an array_element and then it's type is changed to definition via setType of BaseMessageImpl. In this case, the message gets correctly removed from the list of submessages.
The message gets directly added as a definition via the add method of BaseMessageImpl. In this case, the message is incorrectly left in the list of submessages. This gives problems when iterating over the array because the definition message is returned as one of the iterands.
After discussion with Marte and Gerco the proposed solution is to no longer add messages of type="definition" to the list of submessages. Instead, the definition message can be stored in the field definitionMessage. This makes sure the definition message does not show up when iterating over an array.
There are two ways in which a message with type="definition" can be added to an array:
After discussion with Marte and Gerco the proposed solution is to no longer add messages of type="definition" to the list of submessages. Instead, the definition message can be stored in the field definitionMessage. This makes sure the definition message does not show up when iterating over an array.