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

Bug 347964

Summary: Deleting an object from a resource by index
Product: [Modeling] EMF Reporter: Szabolcs Bardy <szbardy>
Component: cdo.coreAssignee: Eike Stepper <stepper>
Status: CLOSED FIXED QA Contact: Eike Stepper <stepper>
Severity: normal    
Priority: P3    
Version: 4.2   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Attachments:
Description Flags
Test case to reproduce the error
stepper: iplog+
Proposed patch stepper: iplog+

Description Szabolcs Bardy CLA 2011-06-01 11:32:40 EDT
Build Identifier: 

When removing an object from a CDOResource contents list by its index - CDOResource.getContents().remove(i) - , if the object to remove has not been resolved yet and it is a CDOElementProxy, an IndexOutOfBoundException is thrown.

The cause of the problem seems to be in the CDOStoreImpl.remove() method, where the element is removed at first from the contents list

oldValue = revision.remove(feature, index);

an afterwards it is tried to be resolved:      

return convertToEMF(eObject, revision, feature, index, oldValue);
    


Reproducible: Always
Comment 1 Szabolcs Bardy CLA 2011-06-01 11:39:16 EDT
Created attachment 197104 [details]
Test case to reproduce the error
Comment 2 Szabolcs Bardy CLA 2011-06-01 11:42:53 EDT
Created attachment 197107 [details]
Proposed patch

It is a proposed patch that fixes this problem, however I don't know whether it may have other impacts.
Comment 3 Eike Stepper CLA 2011-06-23 04:27:44 EDT
Moving all open problem reports to 4.0
Comment 4 Eike Stepper CLA 2012-06-05 07:30:52 EDT
Moving all open bug reports to 4.1 because the release is very near and it's hghly unlikely that there will be spare time to address 4.0 problems.

Please make sure that your patches can be applied against the master branch and that your problem is not already fixed there!!!
Comment 5 Eike Stepper CLA 2012-08-14 22:58:00 EDT
Moving all open issues to 4.2. Open bugs can be ported to 4.1 maintenance after they've been fixed in master.
Comment 6 Eike Stepper CLA 2012-10-31 15:06:20 EDT
Good catch! And sorry that it took so long to get at this.
Comment 7 Eike Stepper CLA 2012-10-31 15:07:49 EDT
commit 2bc303523081db3ffc96a0e7531f2593bdf904d3
Comment 8 Eike Stepper CLA 2012-11-01 02:32:53 EDT
Depending on transaction.options().setStaleReferencePolicy(...) the convertToEMF() call can throw an ObjectNotFoundException (as in Bugzilla_279982_Test).
Comment 9 Eike Stepper CLA 2012-11-01 02:33:20 EDT
The trick is:

      oldValue = revision.get(feature, index);

      try
      {
        oldValue = convertToEMF(eObject, revision, feature, index, oldValue);
      }
      finally
      {
        revision.remove(feature, index);
      }

      return oldValue;
Comment 10 Eike Stepper CLA 2012-11-01 02:34:30 EDT
commit e1fd2d34d3033db38bfc1dabd740681bfa296a1a
Comment 11 Eike Stepper CLA 2013-06-27 03:33:44 EDT
Available in R20130613-1157 (4.2)