HREFDanglingException not expected... [message #676283] |
Fri, 03 June 2011 10:02  |
Eclipse User |
|
|
|
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   |
Eclipse User |
|
|
|
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   |
Eclipse User |
|
|
|
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
|
|
|
|
Powered by
FUDForum. Page generated in 0.04356 seconds