Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [EMF] ResourceSetImpl.getResource does not behave in the same way calling it twice
[EMF] ResourceSetImpl.getResource does not behave in the same way calling it twice [message #1691639] Wed, 08 April 2015 16:37 Go to next message
Laurent Fasani is currently offline Laurent FasaniFriend
Messages: 159
Registered: October 2014
Senior Member
Hello Ed

When calling ResourceSetImpl.getResource, I am facing with what it looks like an incoherence.

Given an URI which does not correspond to anything (for example "platform:/resource/testproject/NonExisting.ecore"), i am calling ResourceSetImpl.getResource(uri, true); with loadOnDemand=true
The resource is not found but, as loadOnDemand=true, the resource is created but then when attempting to load it, a WrappedException is raised.

At second call to ResourceSetImpl.getResource(uri, true);, a resource is returned.

The reason is that at first call the created resource has been set on resourceSet, but the second call just return that resource.

Whatever how it works, in my opinion, both calls should have the same behavior either returning the same resource or raising an exception.

Proposition: Maybe, at first call, when internally catching the ResourceException, the resource could be removed from the resourceSet, so the second call could behave in the same way.

Looking forward to your answer.


Laurent Fasani - Obeo
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: [EMF] ResourceSetImpl.getResource does not behave in the same way calling it twice [message #1691684 is a reply to message #1691639] Thu, 09 April 2015 04:27 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30551
Registered: July 2009
Senior Member
Laurent,

Comments below.

On 08/04/2015 6:37 PM, Laurent Fasani wrote:
> Hello Ed
>
> When calling ResourceSetImpl.getResource, I am facing with what it
> looks like an incoherence.
>
> Given an URI which does not correspond to anything (for example
> "platform:/resource/testproject/NonExisting.ecore"), i am calling
> ResourceSetImpl.getResource(uri, true); with loadOnDemand=true
> The resource is not found but, as loadOnDemand=true, the resource is
> created but then when attempting to load it, a WrappedException is
> raised.
>
> At second call to ResourceSetImpl.getResource(uri, true);, a resource
> is returned.

Yes, that's expected.
>
> The reason is that at first call the created resource has been set on
> resourceSet, but the second call just return that resource.
>
> Whatever how it works, in my opinion, both calls should have the same
> behavior either returning the same resource or raising an exception.
This is long standing behavior and behaves as intended. A resource,
once loaded, will not be loaded again until unloaded.
>
> Proposition: Maybe, at first call, when internally catching the
> ResourceException, the resource could be removed from the resourceSet,
> so the second call could behave in the same way.
Absolutely not, a load failure is generally expensive, and it's often
the case that an exception it thrown, but the resource is mostly
loaded. I.e., if some attribute that's supposed to be a number contains
something that's not a number, an exception will be thrown, but the
entire resource is loaded and only that one attribute's value is not
populated.
>
> Looking forward to your answer.
Note that failures to load are recorded in Resource.getErrors() so you
can examine those to determine which resources have had major or minor
problems when they were loaded.
Re: [EMF] ResourceSetImpl.getResource does not behave in the same way calling it twice [message #1691724 is a reply to message #1691684] Thu, 09 April 2015 09:45 Go to previous message
Laurent Fasani is currently offline Laurent FasaniFriend
Messages: 159
Registered: October 2014
Senior Member
Thanks for your quick reply. I 'll manage with Resource.getErrors() then or more beforehand with
 boolean existsResource = resourceSet.getURIConverter().exists(resourceURI, null);
which allows me not to even try getting the resource.


Laurent Fasani - Obeo
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Previous Topic:Reflective access to generated classes
Next Topic:Extending a metamodel
Goto Forum:
  


Current Time: Mon Oct 21 10:47:52 GMT 2019

Powered by FUDForum. Page generated in 0.02225 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top