Bug 289198 - Exception when removing/reading resource with same path
Summary: Exception when removing/reading resource with same path
Status: NEW
Alias: None
Product: EMF
Classification: Modeling
Component: cdo.core (show other bugs)
Version: 4.13   Edit
Hardware: PC Windows Vista
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-09-11 08:05 EDT by Anders Forsell CLA
Modified: 2020-12-11 10:41 EST (History)
4 users (show)

See Also:


Attachments
Source code for test case (1.83 KB, text/plain)
2009-09-11 08:53 EDT, Anders Forsell CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Anders Forsell CLA 2009-09-11 08:05:37 EDT
I get an exception when removing a resource and then adding a new with the same path:

    CDOResource cdoResource = transaction.getOrCreateResource("/model1");
    transaction.commit();
    cdoResource.getContents().clear();
    transaction.getResourceSet().getResources().remove(cdoResource);
    transaction.commit();
    CDOResourceNode resourceNode = transaction.getResourceNode("/model1");
    CDOResource resource = transaction.getResource("/model1");

    Stack trace:
    Exception in thread "main" org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$1DiagnosticWrappedException: org.eclipse.emf.cdo.util.InvalidURIException: Invalid URI "cdo://c3ca260d-b348-4a67-b99e-df64f6ef421f/model1": java.lang.IllegalStateException: Duplicate ID: CDOResource@OID4
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.handleDemandLoadException(ResourceSetImpl.java:315)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoadHelper(ResourceSetImpl.java:274)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResource(ResourceSetImpl.java:397)
	at org.eclipse.emf.internal.cdo.view.CDOViewImpl.getResource(CDOViewImpl.java:632)
	at org.eclipse.emf.internal.cdo.view.CDOViewImpl.getResource(CDOViewImpl.java:622)
	at com.comsol.model.util.ModelUtil.create(ModelUtil.java:48)
	at Main.main(Main.java:25)
Caused by: org.eclipse.emf.cdo.util.InvalidURIException: Invalid URI "cdo://c3ca260d-b348-4a67-b99e-df64f6ef421f/model1": java.lang.IllegalStateException: Duplicate ID: CDOResource@OID4
	at org.eclipse.emf.internal.cdo.view.CDOViewImpl.registerProxyResource(CDOViewImpl.java:1059)
	at org.eclipse.emf.cdo.eresource.impl.CDOResourceImpl.load(CDOResourceImpl.java:605)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoad(ResourceSetImpl.java:255)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoadHelper(ResourceSetImpl.java:270)
	... 5 more
Comment 1 Eike Stepper CLA 2009-09-11 08:19:53 EDT
Hi Anders, Can you try to write a test case similar to the other ones we have and attach it to this bug? It's really easy, have a look in the o.e.e.cdo.tests plugin and copy one of the Bugzilla_XYZ_Test classes. Bugzillas with test cases are more likely to be fixed very quickly ;-)
Comment 2 Anders Forsell CLA 2009-09-11 08:53:58 EDT
Created attachment 146943 [details]
Source code for test case

I haven't really compiled this and tested it but hopefully it repeats the problem :-)
Comment 3 Simon Mc Duff CLA 2009-09-11 10:05:04 EDT
CDOResourceImpl can be loaded without being in a resourceset and that CDOResourceFactory do not have any context... so it needs to create a new CDOResourceImpl each time a resourceset.createResource() is called... even if we already have it. Could we add a wrapper of CDOResource that delegate to the real one ? I know object identity will be lost... for that object :-(

CDOResourceForWrapper - > Will delegate all its call to CDOResource.

Maybe it will be a good time to create our own ResourceImpl and delegate the behavior to our CDOResource ? In this case, it will work! We use ResourceImpl only from the resourceset...and we have our real object CDOResource that could be access from our objects.!

I will continue to think about something.

Simon
Comment 4 Victor Roldan Betancort CLA 2009-09-11 10:56:41 EDT
Anders,

is this bug for the 2.0 release? If so, please tag it as [maintenance].

Thanks :D

Víctor.
Comment 5 Anders Forsell CLA 2009-09-17 11:07:58 EDT
Hi Victor,

I am not sure I understand what you mean... I found the bug with the 2.0 release and you are asking if I want it fixed in the maintenance release?
Comment 6 Victor Roldan Betancort CLA 2009-09-17 17:57:38 EDT
Hi Anders,

that's the answer :D The 2.0 version is now the maintenance branch, as we've entered in the new development cycle for the helios release, which is CDO version 3.0. So yes, I just to clarify that you found it in 2.0, to tag it as "[maintenance]" to have a visual hint to ease identification of 2.0 bugs :)

We should also check if this bug affects the 3.0 branch.

Cheers,
Víctor.
Comment 7 Anders Forsell CLA 2009-09-27 02:01:57 EDT
This is really a serious issue. See below for a scenario where you delete a CDO resource from the resource set. Later you look if it is available using "hasResource", which returns 'true' (?) and then when getting the resource "getResource" the exception is thrown.

CDOResource cdoResource = transaction.getOrCreateResource("/model1");
transaction.commit();
transaction.getResourceSet().getResources().remove(cdoResource);
transaction.commit();
if (transaction.hasResource("/model1")) {
    // The hasResource will return 'true' ??!!
	cdoResource = transaction.getResource("/model1");
}
Comment 8 Anders Forsell CLA 2009-09-27 03:07:28 EDT
I am taking back my last comment. After discussion with Eike I understand that I have to use resource.delete() to actually delete the resource from the repository.

Thus, this bug does not have to be fixed in 2.0 maintenance anymore.
Comment 9 Eike Stepper CLA 2009-09-27 03:11:12 EDT
Anders found out that he really wanted to delete the resource permanently from the repository, rather than only locally remove it from the resource set. CDOResource.delete() does the trick.

Moving to 3.0 for re-investigation.
Comment 10 Eike Stepper CLA 2010-06-29 04:54:42 EDT
Rebasing all outstanding 3.0 problem reports to version 3.0.1
Comment 11 Eike Stepper CLA 2010-07-07 07:10:38 EDT
Fixing wrong bug version.
Comment 12 Eike Stepper CLA 2011-06-23 04:27:08 EDT
Moving all open problem reports to 4.0
Comment 13 Eike Stepper CLA 2012-06-05 07:29:30 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 14 Eike Stepper CLA 2012-08-14 22:55:45 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 15 Eike Stepper CLA 2013-06-29 12:16:47 EDT
We'll try to address open problems in 4.3 (master) first and then port fixes back to 4.2.
Comment 16 Eike Stepper CLA 2015-07-14 02:18:20 EDT
Moving all open bugzillas to 4.5.
Comment 17 Eike Stepper CLA 2016-07-31 01:01:12 EDT
Moving all unaddressed bugzillas to 4.6.
Comment 18 Eike Stepper CLA 2017-12-28 01:10:37 EST
Moving all open bugs to 4.7
Comment 19 Eike Stepper CLA 2019-11-08 02:07:28 EST
Moving all unresolved issues to version 4.8-
Comment 20 Eike Stepper CLA 2019-12-13 12:47:13 EST
Moving all unresolved issues to version 4.9
Comment 21 Eike Stepper CLA 2020-12-11 10:41:34 EST
Moving to 4.13.