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

Bug 314264

Summary: IndexOutOfBoundsException during branch merge
Product: [Modeling] EMF Reporter: Pascal Lehmann <pascal.lehmann>
Component: cdo.coreAssignee: Eike Stepper <stepper>
Status: CLOSED FIXED QA Contact: Eike Stepper <stepper>
Severity: normal    
Priority: P3    
Version: 3.0   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
TestCase
stepper: iplog+
proposed patch
stepper: iplog+
proposed patch for CDOSingleValueFeatureDelta stepper: iplog+

Description Pascal Lehmann CLA 2010-05-25 09:08:35 EDT
Build Identifier: 3.0

When merging 2 branches, the indices of the FeatureDeltas have to be adjusted. The special case "add element at index 0" does not seem to be handled in adjustAfterRemoval of CDOSingleValueFeatureDelta and CDOMoveFeatureDelta leading to a negative index (-1) and causing an IndexOutOfBoundsException when applying:

java.lang.IndexOutOfBoundsException: Index: -1, Size: 1
	at java.util.ArrayList.add(Unknown Source)
	at org.eclipse.emf.cdo.internal.common.revision.delta.CDOAddFeatureDeltaImpl.apply(CDOAddFeatureDeltaImpl.java:50)
	at org.eclipse.emf.cdo.internal.common.revision.delta.CDOListFeatureDeltaImpl.apply(CDOListFeatureDeltaImpl.java:248)
	at org.eclipse.emf.cdo.internal.common.revision.delta.CDORevisionDeltaImpl.apply(CDORevisionDeltaImpl.java:191)
	at org.eclipse.emf.internal.cdo.transaction.CDOTransactionImpl.applyChangeSetData(CDOTransactionImpl.java:483)
	at org.eclipse.emf.internal.cdo.transaction.CDOTransactionImpl.merge(CDOTransactionImpl.java:358)

The same happens in CDONotificationBuilder, but the problem is not immediately visible.

Reproducible: Always

Steps to Reproduce:
1. Create 2 branches (main and another branch).
2. Remove an element from a containment list in main branch, and add an element to the same list at index 0 in the other branch.
3. merge the other branch to main.
Comment 1 Pascal Lehmann CLA 2010-05-25 09:11:18 EDT
Created attachment 169823 [details]
TestCase

The test case contains two tests:
- one for the merge case.
- one for the notification.
Comment 2 Pascal Lehmann CLA 2010-05-25 09:13:20 EDT
Created attachment 169824 [details]
proposed patch

added a check if index is > 0 before decreasing.
Comment 3 Pascal Lehmann CLA 2010-05-25 09:15:10 EDT
Created attachment 169825 [details]
proposed patch for CDOSingleValueFeatureDelta

added a check if index > 0 before decreasing.
Comment 4 Pascal Lehmann CLA 2010-05-25 09:19:26 EDT
I patched CDOSingleValueFeatureDeltaImpl and CDOMoveFeatureDeltaImpl's adjustAfterRemoval method. However in CDOMoveFeatureDeltaImpl there also happens some index adjusting in the affectIndices method, which I didn't check and which also might need the > 0 check.


1) The number of lines that you added/changed is smaller than 250.
confirmed
2) You are the only author of these changed lines.
confirmed
3) You apply the EPL to these changed lines.
confirmed
Comment 5 Eike Stepper CLA 2010-05-25 10:11:23 EDT
Thank you Pascal. The second test case (testNotificationBuilderTest) passes with the patches being applied.

But the first one (testMergeTest) still fails and the cause seems unrelated to this bugzilla. It seems more related with bug 312534. For now I commented out the first test case until you have a chance to try it and give feedback.

Committed to HEAD.
Comment 6 Eike Stepper CLA 2010-05-25 10:54:53 EDT
Okay, included the first test case again.

Committed to HEAD.
Comment 7 Eike Stepper CLA 2010-06-29 04:35:59 EDT
Available in 3.0 GA:
http://download.eclipse.org/modeling/emf/cdo/updates/3.0-releases/