Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 330038

Summary: IndexOutOfBoundsException in gallery sample
Product: z_Archived Reporter: Konstantin Komissarchik <konstantin>
Component: SapphireAssignee: Konstantin Komissarchik <konstantin>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: ling.hao
Version: unspecified   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:

Description Konstantin Komissarchik CLA 2010-11-11 14:45:18 EST
Reported by Ling Hao:
=====================

Case 1:

1. sapphire-gallery.xml -> List property editor 
2. add a reference
3. edit the reference and clear the content and get the exception. 

Case 2:

1. sapphire-gallery.xml -> Actions 
2. add a name
3. edit the name and clear the content and get the exception. 
 
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.RangeCheck(ArrayList.java:547)
at java.util.ArrayList.get(ArrayList.java:322)
at org.eclipse.sapphire.modeling.xml.XmlPath.getSegment(XmlPath.java:97)
at org.eclipse.sapphire.modeling.xml.XmlElement.removeChildNode(XmlElement.java:797)
at org.eclipse.sapphire.modeling.xml.XmlElement.removeChildNode(XmlElement.java:788)
at org.eclipse.sapphire.modeling.xml.XmlElement.setChildNodeText(XmlElement.java:771)
at org.eclipse.sapphire.modeling.xml.StandardXmlValueBindingImpl.write(StandardXmlValueBindingImpl.java:161)
Comment 1 Konstantin Komissarchik CLA 2010-11-11 14:47:50 EST
The initial fix is to adjust xml binding specification:

The following change is necessary to the Name property in IValuePropertyActionsGalleryReference and IValuePropertyActionsGalleryEntity.

Original: @XmlBinding( path = "" )
Fix: @XmlValueBinding( path = "", removeNodeOnSetIfNull = false )

Explanation of the problem:

What’s going on is that default xml value binding will remove bound XML node when the property is set to null. This is generally appropriate, but in this case the property is bound to the same XML element as its parent model element (path="" specification). Removing the xml element causes havoc for the parent model element.

Leaving this bug open to track making xml binding smarter to avoid this situation in the first place.
Comment 2 Konstantin Komissarchik CLA 2010-12-01 17:53:55 EST
Fixed the underlying issue and reverted the workarounds in samples. The real fix was to ignore removeNodeOnSetIfNull setting if path is empty (self reference).
Comment 3 Ling Hao CLA 2011-01-05 16:43:24 EST
Verified.