Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 314264 - IndexOutOfBoundsException during branch merge
Summary: IndexOutOfBoundsException during branch merge
Status: CLOSED FIXED
Alias: None
Product: EMF
Classification: Modeling
Component: cdo.core (show other bugs)
Version: 3.0   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Eike Stepper CLA
QA Contact: Eike Stepper CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-05-25 09:08 EDT by Pascal Lehmann CLA
Modified: 2010-06-29 09:20 EDT (History)
0 users

See Also:


Attachments
TestCase (4.42 KB, application/octet-stream)
2010-05-25 09:11 EDT, Pascal Lehmann CLA
stepper: iplog+
Details
proposed patch (1.02 KB, patch)
2010-05-25 09:13 EDT, Pascal Lehmann CLA
stepper: iplog+
Details | Diff
proposed patch for CDOSingleValueFeatureDelta (947 bytes, patch)
2010-05-25 09:15 EDT, Pascal Lehmann CLA
stepper: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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/