Skip to main content



      Home
Home » Modeling » EMF » HREFDanglingException not expected...
HREFDanglingException not expected... [message #676283] Fri, 03 June 2011 10:02 Go to next message
Eclipse UserFriend
Hello, I am getting an HREFDanglingException that I would not expect to find...

I wrote a method that should get every dangling EObject and add it to the resource so that no dangling objects remain and the exception does not appear. This is the code... it doesn't work for some reason, can you spot it?


      ...
      for (EObject eo : resource.getContents()){
        inspect(eo,r);
     }
    resource.save(new HashMap<Object,Object>());  // -> DanglingHREFException!
      ...


	private static void inspect(EObject eo, Resource r) {
		if (eo==null) return;
		if (eo.eResource()==null){
			throw new IllegalArgumentException();
		}
		EClass ec = eo.eClass();
		for (EReference er : ec.getEReferences()) {
			if (er.isContainment()) {
				if (er.isMany()) {
					for (EObject sub : (List<EObject>) eo.eGet(er)) {
						inspect(sub,r);
					}
				} else {
					inspect((EObject) eo.eGet(er),r);
				}
			} else {
				if (er.isMany()) {
					for (EObject sub : (List<EObject>) eo.eGet(er)) {
						if (sub.eResource() == null) {
							r.getContents().add(sub);
							inspect(sub, r);
						}
					}
				} else {
					EObject sub = (EObject) eo.eGet(er);
					if (sub != null) {
						if (sub.eResource() == null) {
							r.getContents().add(sub);
							inspect(sub, r);
						}
					}
				}
			}
		}
	}



I tried to catch the DanglingHREFException (which is inside an IOWrappedException). Unfortunately the exception does not contain a reference to the dangling eobject so I can not inspect it...

Federico
Re: HREFDanglingException not expected... [message #687141 is a reply to message #676283] Fri, 03 June 2011 13:34 Go to previous messageGo to next message
Eclipse UserFriend
Federico,

Comments below.

Federico Tomassetti wrote:
> Hello, I am getting an HREFDanglingException that I would not expect
> to find...
>
> I wrote a method that should get every dangling EObject and add it to
> the resource so that no dangling objects remain and the exception does
> not appear. This is the code... it doesn't work for some reason, can
> you spot it?
>
>
>
> ...
> for (EObject eo : resource.getContents()){
> inspect(eo,r);
> }
> resource.save(new HashMap<Object,Object>()); // ->
> DanglingHREFException!
> ...
>
>
> private static void inspect(EObject eo, Resource r) {
> if (eo==null) return;
> if (eo.eResource()==null){
> throw new IllegalArgumentException();
> }
> EClass ec = eo.eClass();
> for (EReference er : ec.getEReferences()) {
Should this be getEAllReferences()?
> if (er.isContainment()) {
> if (er.isMany()) {
> for (EObject sub : (List<EObject>) eo.eGet(er)) {
> inspect(sub,r);
Do you know that Resource.getAllContents() will walk the whole
containment tree without all this logic?
> }
> } else {
> inspect((EObject) eo.eGet(er),r);
> }
> } else {
EObject.eCrossReferences is useful for easily visiting all referenced
objects.
> if (er.isMany()) {
> for (EObject sub : (List<EObject>) eo.eGet(er)) {
> if (sub.eResource() == null) {
> r.getContents().add(sub);
> inspect(sub, r);
> }
> }
> } else {
> EObject sub = (EObject) eo.eGet(er);
> if (sub != null) {
> if (sub.eResource() == null) {
> r.getContents().add(sub);
> inspect(sub, r);
> }
> }
> }
> }
> }
> }
>
>
>
> I tried to catch the DanglingHREFException (which is inside an
> IOWrappedException). Unfortunately the exception does not contain a
> reference to the dangling eobject so I can not inspect it...
What's stopping you from setting an exception breakpoint, or a
breakpoint on the constructor for the exception?

> Federico
Re: HREFDanglingException not expected... [message #687380 is a reply to message #676283] Fri, 03 June 2011 13:34 Go to previous messageGo to next message
Eclipse UserFriend
Federico,

Comments below.

Federico Tomassetti wrote:
> Hello, I am getting an HREFDanglingException that I would not expect
> to find...
>
> I wrote a method that should get every dangling EObject and add it to
> the resource so that no dangling objects remain and the exception does
> not appear. This is the code... it doesn't work for some reason, can
> you spot it?
>
>
>
> ...
> for (EObject eo : resource.getContents()){
> inspect(eo,r);
> }
> resource.save(new HashMap<Object,Object>()); // ->
> DanglingHREFException!
> ...
>
>
> private static void inspect(EObject eo, Resource r) {
> if (eo==null) return;
> if (eo.eResource()==null){
> throw new IllegalArgumentException();
> }
> EClass ec = eo.eClass();
> for (EReference er : ec.getEReferences()) {
Should this be getEAllReferences()?
> if (er.isContainment()) {
> if (er.isMany()) {
> for (EObject sub : (List<EObject>) eo.eGet(er)) {
> inspect(sub,r);
Do you know that Resource.getAllContents() will walk the whole
containment tree without all this logic?
> }
> } else {
> inspect((EObject) eo.eGet(er),r);
> }
> } else {
EObject.eCrossReferences is useful for easily visiting all referenced
objects.
> if (er.isMany()) {
> for (EObject sub : (List<EObject>) eo.eGet(er)) {
> if (sub.eResource() == null) {
> r.getContents().add(sub);
> inspect(sub, r);
> }
> }
> } else {
> EObject sub = (EObject) eo.eGet(er);
> if (sub != null) {
> if (sub.eResource() == null) {
> r.getContents().add(sub);
> inspect(sub, r);
> }
> }
> }
> }
> }
> }
>
>
>
> I tried to catch the DanglingHREFException (which is inside an
> IOWrappedException). Unfortunately the exception does not contain a
> reference to the dangling eobject so I can not inspect it...
What's stopping you from setting an exception breakpoint, or a
breakpoint on the constructor for the exception?

> Federico
Re: HREFDanglingException not expected... [message #687769 is a reply to message #687141] Thu, 23 June 2011 03:42 Go to previous message
Eclipse UserFriend
Well, the main reason preventing me from using an exception breakbpoint was the fact I did not know about this feature... there are absolutely too many features in Eclipse!

Thanks for your advices, problem solved Smile

Federico
Previous Topic:EMF update site is outdated?
Next Topic:Commit of one transaction results in inactive other transaction
Goto Forum:
  


Current Time: Wed Jul 23 17:50:02 EDT 2025

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

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

Back to the top