Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 322277 - Math error in FastList.remove(Object)
Summary: Math error in FastList.remove(Object)
Status: CLOSED FIXED
Alias: None
Product: EMF
Classification: Modeling
Component: cdo.net4j (show other bugs)
Version: 3.0   Edit
Hardware: All All
: P3 major (vote)
Target Milestone: ---   Edit
Assignee: Caspar D. CLA
QA Contact: Eike Stepper CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-08-10 15:30 EDT by Brendan CLA
Modified: 2012-09-21 06:51 EDT (History)
1 user (show)

See Also:
stepper: review+


Attachments
Patch (2.07 KB, patch)
2010-08-10 23:39 EDT, Caspar D. CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Brendan CLA 2010-08-10 15:30:28 EDT
Build Identifier: 3.0.0v20100614-1655

Presently the FastList method "remove" appears to have an error that causes it to not copy some of the elements while it builds the new array.  The resulting list consequently contains at least one null element.  This frequently causes issues in CDO when the transaction tries to notify its TransactionHandler objects, as it inevitably throws a NullPointerException.

Given a test case:

FastList(x, y, z)

The operation

FastList.remove(y)

will result in a new list

FastList(x, null)

After looking at the code I see that line 84 reads

if (i + 1 < length - 1)

I believe that it should instead be

if (i + 1 =< length - 1)

Unfortunately this is very problematic in relation to CDO because CDOTransaction uses FastList and the act of removing a TransactionHandler will almost invariably induce instability by adding a null element and completely dropping a valid element from the list.

Reproducible: Always

Steps to Reproduce:
1. Create a FastList
2. Add 3 items to it
3. Remove the second item

The underlying array will now contain a null item in the second index and will not have copied the third item.
Comment 1 Caspar D. CLA 2010-08-10 23:39:13 EDT
Created attachment 176291 [details]
Patch

Funny that this slipped through the unit tests; the problem only 
occurs for removal of the penultimate element...

Anyway, here's a patch including a testcase (added to 
FastListTest.java).
Comment 2 Caspar D. CLA 2010-08-11 04:06:55 EDT
Committed to R3_0_maintenance
Comment 3 Eike Stepper CLA 2011-06-23 04:27:02 EDT
Moving all open problem reports to 4.0
Comment 4 Eike Stepper CLA 2012-09-21 06:37:04 EDT
Undoing accidental version change.
Comment 5 Eike Stepper CLA 2012-09-21 06:51:33 EDT
Closing.