pablocp/liferay-portal — pull request #6 by marcellustavares (2014-06-17 12:46:56+00:00)
Title: [TECHNICAL-SUPPORT] LPS-47661 ArrayIndexOutOfBoundsException occurs during content edition if the Structure has been edited

Hi Marcellus, @juliocamarero,

this issue is strictly related to DDM Structures, however, it affects to WCM, Documents and Media and Dynamic Data Lists as well.

The problem is the following:
if there is already an existing content created from a structure, modifying the structure could cause serious problems. Although on the UI we have a warning message during the structure edition ("There are content references to this structure. You may lose data if a field name is renamed or removed."), in unlucky cases ArrayIndexOutOfBoundsException occurs when we try to edit the content and the fields don't render properly.

Despite the fact that it is not recommended to edit a structure which is already used, I think the portal should handle more robustly these cases.

Right now the behavior is unpredictable, as the process tries to go through the fields
sequentially, using the the new order coming from the structure, but the content's fields remained the same.

Changing a structure with many repeatable and/or child fields creates a complex problem, as it is not easy to restore the content after it. Imagine a structure with two repeatable parent/child fields than switch them, so the child field became the parent field...
Even though probably nobody would like to complicate his life so badly, in my opinion, the portal should have some kind of fallback logic.

My idea is the following:
While we are processing the fields with the order coming from the structure, search for the first unprocessed field with the same name. According to my tests this fix solves the problem when the fields are switched at the same level. Furthermore a simple check prevents the ArrayIndexOutOfBoundsException, so the content remains editable.

Could you please review my changes? How we should handle this problem?
If I missed something, or you have a better idea, please point me to the right direction.

Thank you in advance,
Tamás