Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » editingDomain sometimes null when using AdapterFactoryEditingDomain.getEditingDomainFor (EObject)
editingDomain sometimes null when using AdapterFactoryEditingDomain.getEditingDomainFor (EObject) [message #428638] Wed, 25 March 2009 16:18 Go to next message
Eclipse UserFriend
Originally posted by: talon.karrde.sw.gmail.com

Hello,

First of all, I'm so sorry for english errors I have made in the
following post.

I'm using the following code to retrieve the editingDomain:

EditingDomain editingDomain =
AdapterFactoryEditingDomain.getEditingDomainFor (_input);

Sometimes this method returns null. I’ve read in this newsgroup that it
comes from a non-existent Resource in the EObject. Most of the time,
EObject contains a resource, but from time to time, it does not.

After a series of tests, I've often noticed this while building. I'm
using a builder that generates code from the Resource file. I'm
wondering if it can be the origin of this issue.

Regarding the resolution of the bug, if I use the editingDomain defined
in the generated editor (by initializeEditingDomain function ()) what
impact this might have on the plug-in behavior? Is an EObject with a
null Resource can generate some crashes?

Thanks,
François
Re: editingDomain sometimes null when using AdapterFactoryEditingDomain.getEditingDomainFor (EObject [message #428641 is a reply to message #428638] Wed, 25 March 2009 16:49 Go to previous messageGo to next message
maatari is currently offline maatariFriend
Messages: 74
Registered: July 2009
Member
Hi ,

An Eobject without a resource is likely to cause you a dangling reference.
Meaning simply that you can't save it. More specifically, it means that in
your model it doesn't have any container. So, no crash but problem when
saving :-(

However I don't know nothing about builder. So, I hope it helps a bit.

Kind regards,
Maatari



On 3/25/09 5:18 PM, in article gqdlc5$n5j$1@build.eclipse.org, "François
Robert" <talon.karrde.sw@gmail.com> wrote:

> Hello,
>
> First of all, I'm so sorry for english errors I have made in the
> following post.
>
> I'm using the following code to retrieve the editingDomain:
>
> EditingDomain editingDomain =
> AdapterFactoryEditingDomain.getEditingDomainFor (_input);
>
> Sometimes this method returns null. I¹ve read in this newsgroup that it
> comes from a non-existent Resource in the EObject. Most of the time,
> EObject contains a resource, but from time to time, it does not.
>
> After a series of tests, I've often noticed this while building. I'm
> using a builder that generates code from the Resource file. I'm
> wondering if it can be the origin of this issue.
>
> Regarding the resolution of the bug, if I use the editingDomain defined
> in the generated editor (by initializeEditingDomain function ()) what
> impact this might have on the plug-in behavior? Is an EObject with a
> null Resource can generate some crashes?
>
> Thanks,
> François
Re: editingDomain sometimes null when using AdapterFactoryEditingDomain.getEditingDomainFor (EObject [message #428669 is a reply to message #428641] Thu, 26 March 2009 11:44 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: talon.karrde.sw.gmail.com

Hi,

Thanks for your quick answer Daniel, you inspired me.

Since the model doesn't have any container, I tried to attach one using
this piece of code:
if (AdapterFactoryEditingDomain.getEditingDomainFor(_input) == null) {
for (Resource r :
_editor.getEditingDomain().getResourceSet().getResources())
r.getContents().add(_input);
}

But it won't fix the problem, I get a java.lang.ClassCastException.
I'm completely lost with this bug, I just don't understand why the model
loses his Resource.

François

Daniel OKOUYA wrote:
> Hi ,
>
> An Eobject without a resource is likely to cause you a dangling reference.
> Meaning simply that you can't save it. More specifically, it means that in
> your model it doesn't have any container. So, no crash but problem when
> saving :-(
>
> However I don't know nothing about builder. So, I hope it helps a bit.
>
> Kind regards,
> Maatari
>
>
>
> On 3/25/09 5:18 PM, in article gqdlc5$n5j$1@build.eclipse.org, "François
> Robert" <talon.karrde.sw@gmail.com> wrote:
>
>> Hello,
>>
>> First of all, I'm so sorry for english errors I have made in the
>> following post.
>>
>> I'm using the following code to retrieve the editingDomain:
>>
>> EditingDomain editingDomain =
>> AdapterFactoryEditingDomain.getEditingDomainFor (_input);
>>
>> Sometimes this method returns null. I¹ve read in this newsgroup that it
>> comes from a non-existent Resource in the EObject. Most of the time,
>> EObject contains a resource, but from time to time, it does not.
>>
>> After a series of tests, I've often noticed this while building. I'm
>> using a builder that generates code from the Resource file. I'm
>> wondering if it can be the origin of this issue.
>>
>> Regarding the resolution of the bug, if I use the editingDomain defined
>> in the generated editor (by initializeEditingDomain function ()) what
>> impact this might have on the plug-in behavior? Is an EObject with a
>> null Resource can generate some crashes?
>>
>> Thanks,
>> François
>
Re: editingDomain sometimes null when using AdapterFactoryEditingDomain.getEditingDomainFor (EObject [message #428670 is a reply to message #428669] Thu, 26 March 2009 11:57 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
François,

Comments below.

François Robert wrote:
> Hi,
>
> Thanks for your quick answer Daniel, you inspired me.
>
> Since the model doesn't have any container, I tried to attach one
> using this piece of code:
> if (AdapterFactoryEditingDomain.getEditingDomainFor(_input) == null) {
> for (Resource r :
> _editor.getEditingDomain().getResourceSet().getResources())
> r.getContents().add(_input);
> }
>
> But it won't fix the problem, I get a java.lang.ClassCastException.
If you already know the editing domain, why do you need to get it? Do
you notice that you're adding _input to every single resource? That
can't be good given it can only be contained by one. Also, making
changes to the model that don't use commands can't be good either.
> I'm completely lost with this bug, I just don't understand why the
> model loses his Resource.
Given I don't know what your builder is doing, I can't say. It's of
course possible that you create new objects and set non-containment
references to them without having also added that object to a resource's
contents or to some other container object's containment reference.
I.e., that your model didn't lose its resource but rather never had
one. Losing the resource would involve of course the inverse, i.e.,
removing it from resource.getContents() or some container's containment
reference...

It's pretty easy to find dangling references. Iterate over the
reosurce's getAllContents, and for each EObject, iterator over the
eCrossReferences(). If any of such a cross referenced EObject has
eResource() null, then it's a dangling reference.
Diagnostician.INSTANCE.validate will complain about them too...
>
> François
>
> Daniel OKOUYA wrote:
>> Hi ,
>>
>> An Eobject without a resource is likely to cause you a dangling
>> reference.
>> Meaning simply that you can't save it. More specifically, it means
>> that in
>> your model it doesn't have any container. So, no crash but problem when
>> saving :-(
>>
>> However I don't know nothing about builder. So, I hope it helps a bit.
>>
>> Kind regards,
>> Maatari
>>
>>
>>
>> On 3/25/09 5:18 PM, in article gqdlc5$n5j$1@build.eclipse.org, "François
>> Robert" <talon.karrde.sw@gmail.com> wrote:
>>
>>> Hello,
>>>
>>> First of all, I'm so sorry for english errors I have made in the
>>> following post.
>>>
>>> I'm using the following code to retrieve the editingDomain:
>>>
>>> EditingDomain editingDomain =
>>> AdapterFactoryEditingDomain.getEditingDomainFor (_input);
>>>
>>> Sometimes this method returns null. I¹ve read in this newsgroup that it
>>> comes from a non-existent Resource in the EObject. Most of the time,
>>> EObject contains a resource, but from time to time, it does not.
>>>
>>> After a series of tests, I've often noticed this while building. I'm
>>> using a builder that generates code from the Resource file. I'm
>>> wondering if it can be the origin of this issue.
>>>
>>> Regarding the resolution of the bug, if I use the editingDomain defined
>>> in the generated editor (by initializeEditingDomain function ()) what
>>> impact this might have on the plug-in behavior? Is an EObject with a
>>> null Resource can generate some crashes?
>>>
>>> Thanks,
>>> François
>>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: editingDomain sometimes null when using AdapterFactoryEditingDomain.getEditingDomainFor (EObject [message #428696 is a reply to message #428670] Thu, 26 March 2009 18:28 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: talon.karrde.sw.gmail.com

Hi,

Thanks Ed for your post, it helped a lot.

I actually found what was wrong in my model, every Eobject in the
TreeViewer is a proxy but when I iterate through
Resource.getAllContents, EObject are not proxies. I'm assuming that's
because the builder is using the resource file during the EMF model loading.

So I'm wondering if I can resolve proxies in the entire TreeViewer? If
not, is there another way to resolve this issue?

Thanks,
François

Ed Merks wrote:
> François,
>
> Comments below.
>
> François Robert wrote:
>> Hi,
>>
>> Thanks for your quick answer Daniel, you inspired me.
>>
>> Since the model doesn't have any container, I tried to attach one
>> using this piece of code:
>> if (AdapterFactoryEditingDomain.getEditingDomainFor(_input) == null) {
>> for (Resource r :
>> _editor.getEditingDomain().getResourceSet().getResources())
>> r.getContents().add(_input);
>> }
>>
>> But it won't fix the problem, I get a java.lang.ClassCastException.
> If you already know the editing domain, why do you need to get it? Do
> you notice that you're adding _input to every single resource? That
> can't be good given it can only be contained by one. Also, making
> changes to the model that don't use commands can't be good either.
>> I'm completely lost with this bug, I just don't understand why the
>> model loses his Resource.
> Given I don't know what your builder is doing, I can't say. It's of
> course possible that you create new objects and set non-containment
> references to them without having also added that object to a resource's
> contents or to some other container object's containment reference.
> I.e., that your model didn't lose its resource but rather never had
> one. Losing the resource would involve of course the inverse, i.e.,
> removing it from resource.getContents() or some container's containment
> reference...
> It's pretty easy to find dangling references. Iterate over the
> reosurce's getAllContents, and for each EObject, iterator over the
> eCrossReferences(). If any of such a cross referenced EObject has
> eResource() null, then it's a dangling reference.
> Diagnostician.INSTANCE.validate will complain about them too...
>>
>> François
>>
>> Daniel OKOUYA wrote:
>>> Hi ,
>>>
>>> An Eobject without a resource is likely to cause you a dangling
>>> reference.
>>> Meaning simply that you can't save it. More specifically, it means
>>> that in
>>> your model it doesn't have any container. So, no crash but problem when
>>> saving :-(
>>>
>>> However I don't know nothing about builder. So, I hope it helps a bit.
>>>
>>> Kind regards,
>>> Maatari
>>>
>>>
>>>
>>> On 3/25/09 5:18 PM, in article gqdlc5$n5j$1@build.eclipse.org, "François
>>> Robert" <talon.karrde.sw@gmail.com> wrote:
>>>
>>>> Hello,
>>>>
>>>> First of all, I'm so sorry for english errors I have made in the
>>>> following post.
>>>>
>>>> I'm using the following code to retrieve the editingDomain:
>>>>
>>>> EditingDomain editingDomain =
>>>> AdapterFactoryEditingDomain.getEditingDomainFor (_input);
>>>>
>>>> Sometimes this method returns null. I¹ve read in this newsgroup that it
>>>> comes from a non-existent Resource in the EObject. Most of the time,
>>>> EObject contains a resource, but from time to time, it does not.
>>>>
>>>> After a series of tests, I've often noticed this while building. I'm
>>>> using a builder that generates code from the Resource file. I'm
>>>> wondering if it can be the origin of this issue.
>>>>
>>>> Regarding the resolution of the bug, if I use the editingDomain defined
>>>> in the generated editor (by initializeEditingDomain function ()) what
>>>> impact this might have on the plug-in behavior? Is an EObject with a
>>>> null Resource can generate some crashes?
>>>>
>>>> Thanks,
>>>> François
>>>
Re: editingDomain sometimes null when using AdapterFactoryEditingDomain.getEditingDomainFor (EObject [message #428704 is a reply to message #428696] Fri, 27 March 2009 01:33 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
François,

It sounds like a resource delta caused a resource to be unloaded then
and then be reloaded with the old contents being converted to proxies
and remaining as inputs to the tree view. It sounds like you'd want the
resource's new contents to become the new input to the view. You could
listen for the resource's contents changing to set the input to the view
again.

François Robert wrote:
> Hi,
>
> Thanks Ed for your post, it helped a lot.
>
> I actually found what was wrong in my model, every Eobject in the
> TreeViewer is a proxy but when I iterate through
> Resource.getAllContents, EObject are not proxies. I'm assuming that's
> because the builder is using the resource file during the EMF model
> loading.
>
> So I'm wondering if I can resolve proxies in the entire TreeViewer? If
> not, is there another way to resolve this issue?
>
> Thanks,
> François
>
> Ed Merks wrote:
>> François,
>>
>> Comments below.
>>
>> François Robert wrote:
>>> Hi,
>>>
>>> Thanks for your quick answer Daniel, you inspired me.
>>>
>>> Since the model doesn't have any container, I tried to attach one
>>> using this piece of code:
>>> if (AdapterFactoryEditingDomain.getEditingDomainFor(_input) == null) {
>>> for (Resource r :
>>> _editor.getEditingDomain().getResourceSet().getResources())
>>> r.getContents().add(_input);
>>> }
>>>
>>> But it won't fix the problem, I get a java.lang.ClassCastException.
>> If you already know the editing domain, why do you need to get it?
>> Do you notice that you're adding _input to every single resource?
>> That can't be good given it can only be contained by one. Also,
>> making changes to the model that don't use commands can't be good
>> either.
>>> I'm completely lost with this bug, I just don't understand why the
>>> model loses his Resource.
>> Given I don't know what your builder is doing, I can't say. It's of
>> course possible that you create new objects and set non-containment
>> references to them without having also added that object to a
>> resource's contents or to some other container object's containment
>> reference. I.e., that your model didn't lose its resource but rather
>> never had one. Losing the resource would involve of course the
>> inverse, i.e., removing it from resource.getContents() or some
>> container's containment reference...
>> It's pretty easy to find dangling references. Iterate over the
>> reosurce's getAllContents, and for each EObject, iterator over the
>> eCrossReferences(). If any of such a cross referenced EObject has
>> eResource() null, then it's a dangling reference.
>> Diagnostician.INSTANCE.validate will complain about them too...
>>>
>>> François
>>>
>>> Daniel OKOUYA wrote:
>>>> Hi ,
>>>>
>>>> An Eobject without a resource is likely to cause you a dangling
>>>> reference.
>>>> Meaning simply that you can't save it. More specifically, it means
>>>> that in
>>>> your model it doesn't have any container. So, no crash but problem
>>>> when
>>>> saving :-(
>>>>
>>>> However I don't know nothing about builder. So, I hope it helps a bit.
>>>>
>>>> Kind regards,
>>>> Maatari
>>>>
>>>>
>>>>
>>>> On 3/25/09 5:18 PM, in article gqdlc5$n5j$1@build.eclipse.org,
>>>> "François
>>>> Robert" <talon.karrde.sw@gmail.com> wrote:
>>>>
>>>>> Hello,
>>>>>
>>>>> First of all, I'm so sorry for english errors I have made in the
>>>>> following post.
>>>>>
>>>>> I'm using the following code to retrieve the editingDomain:
>>>>>
>>>>> EditingDomain editingDomain =
>>>>> AdapterFactoryEditingDomain.getEditingDomainFor (_input);
>>>>>
>>>>> Sometimes this method returns null. I¹ve read in this newsgroup
>>>>> that it
>>>>> comes from a non-existent Resource in the EObject. Most of the time,
>>>>> EObject contains a resource, but from time to time, it does not.
>>>>>
>>>>> After a series of tests, I've often noticed this while building. I'm
>>>>> using a builder that generates code from the Resource file. I'm
>>>>> wondering if it can be the origin of this issue.
>>>>>
>>>>> Regarding the resolution of the bug, if I use the editingDomain
>>>>> defined
>>>>> in the generated editor (by initializeEditingDomain function ()) what
>>>>> impact this might have on the plug-in behavior? Is an EObject with a
>>>>> null Resource can generate some crashes?
>>>>>
>>>>> Thanks,
>>>>> François
>>>>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Teneo Hibernate Mapping Exception
Next Topic:Question about EMF Validation Example
Goto Forum:
  


Current Time: Tue Apr 23 09:50:11 GMT 2024

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

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

Back to the top