Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 363839

Summary: Stackoverflow when visiting a Part
Product: z_Archived Reporter: Bart Van Campenhout <Bart_van_campenhout>
Component: EDTAssignee: Project Inbox <edt.mofmodel-inbox>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: pharmon
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description Bart Van Campenhout CLA 2011-11-15 10:41:46 EST
From a plug in environmet, I'm trying to visit all EGL subparts like functions, records,.. for a certain Part (program i this particular case).

Here's the code for my class:

package be.asist.birep.decompile;

import java.util.HashSet;
import java.util.Set;

import org.eclipse.edt.mof.egl.Element;
import org.eclipse.edt.mof.egl.Function;
import org.eclipse.edt.mof.egl.Program;
import org.eclipse.edt.mof.impl.AbstractVisitor;

public class SubPartParser extends AbstractVisitor{
	HashSet<Element> subParts = new HashSet<Element>();
	boolean visitResultValue = true;

	public SubPartParser() {
	}

	public Set<Element> getSubPartsForPart(Element part) {
		try {
			subParts = new HashSet<Element>();
			part.accept(this);
			return subParts;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	

	public boolean visit(Function obj) {
		subParts.add((Element)obj);
		return true;
	}
	public boolean visit(Program obj) {
		subParts.add((Element)obj);
		return true;
	}		
}



when getSubPartsForPart is called for the Program Part in the attached file, I get a StackOverflowException.

From the console:
java.lang.StackOverflowError
	at java.lang.reflect.AccessibleObject.<init>(Unknown Source)
	at java.lang.reflect.Method.<init>(Unknown Source)
	at java.lang.reflect.Method.copy(Unknown Source)
	at java.lang.reflect.ReflectAccess.copyMethod(Unknown Source)
	at sun.reflect.ReflectionFactory.copyMethod(Unknown Source)
	at java.lang.Class.copyMethods(Unknown Source)
	at java.lang.Class.getMethods(Unknown Source)
	at org.eclipse.edt.mof.impl.AbstractVisitor.primGetMethod(AbstractVisitor.java:148)
	at org.eclipse.edt.mof.impl.AbstractVisitor.getMethod(AbstractVisitor.java:172)
	at org.eclipse.edt.mof.impl.AbstractVisitor.getMethod(AbstractVisitor.java:178)
	at org.eclipse.edt.mof.impl.AbstractVisitor.getMethod(AbstractVisitor.java:178)
	at org.eclipse.edt.mof.impl.AbstractVisitor.getMethod(AbstractVisitor.java:178)
	at org.eclipse.edt.mof.impl.AbstractVisitor.getMethod(AbstractVisitor.java:178)
	at org.eclipse.edt.mof.impl.AbstractVisitor.getMethod(AbstractVisitor.java:178)
	at org.eclipse.edt.mof.impl.AbstractVisitor.getMethod(AbstractVisitor.java:178)
	at org.eclipse.edt.mof.impl.AbstractVisitor.getMethod(AbstractVisitor.java:178)
	at org.eclipse.edt.mof.impl.AbstractVisitor.invokeVisit(AbstractVisitor.java:124)
	at org.eclipse.edt.mof.impl.AbstractVisitor.primVisit(AbstractVisitor.java:102)
	at org.eclipse.edt.mof.impl.InternalEObject.accept(InternalEObject.java:206)
	at org.eclipse.edt.mof.impl.InternalEObject.visitChildren(InternalEObject.java:230)
	at org.eclipse.edt.mof.impl.InternalEObject.accept(InternalEObject.java:208)
	at org.eclipse.edt.mof.impl.InternalEObject.visitChildren(InternalEObject.java:243)
	at org.eclipse.edt.mof.impl.InternalEObject.accept(InternalEObject.java:208)
	at org.eclipse.edt.mof.impl.InternalEObject.visitChildren(InternalEObject.java:243)
	at org.eclipse.edt.mof.impl.InternalEObject.accept(InternalEObject.java:208)
	at org.eclipse.edt.mof.impl.InternalEObject.visitChildren(InternalEObject.java:243)
	at org.eclipse.edt.mof.impl.InternalEObject.accept(InternalEObject.java:208)
	at org.eclipse.edt.mof.impl.InternalEObject.visitChildren(InternalEObject.java:230)
	at org.eclipse.edt.mof.impl.InternalEObject.accept(InternalEObject.java:208)
	at org.eclipse.edt.mof.impl.InternalEObject.visitChildren(InternalEObject.java:243)
	at org.eclipse.edt.mof.impl.InternalEObject.accept(InternalEObject.java:208)
	at org.eclipse.edt.mof.impl.InternalEObject.visitChildren(InternalEObject.java:243)
	at org.eclipse.edt.mof.impl.InternalEObject.accept(InternalEObject.java:208)
	at org.eclipse.edt.mof.impl.InternalEObject.visitChildren(InternalEObject.java:243)
	at org.eclipse.edt.mof.impl.InternalEObject.accept(InternalEObject.java:208)
	at org.eclipse.edt.mof.impl.InternalEObject.visitChildren(InternalEObject.java:230)
	at org.eclipse.edt.mof.impl.InternalEObject.accept(InternalEObject.java:208)
	at org.eclipse.edt.mof.impl.InternalEObject.visitChildren(InternalEObject.java:243)
	at org.eclipse.edt.mof.impl.InternalEObject.accept(InternalEObject.java:208)
	at org.eclipse.edt.mof.impl.InternalEObject.visitChildren(InternalEObject.java:243)
	at org.eclipse.edt.mof.impl.InternalEObject.accept(InternalEObject.java:208)
	at org.eclipse.edt.mof.impl.InternalEObject.visitChildren(InternalEObject.java:243)
	at org.eclipse.edt.mof.impl.InternalEObject.accept(InternalEObject.java:208)
....
Comment 1 Paul Harmon CLA 2011-11-15 12:42:40 EST
Bart,

Can you attach the EGL file?

Thanks,

Paul
Comment 2 Paul Harmon CLA 2011-11-15 12:53:54 EST
Bart,

It just occurred to me what is probably wrong with your visitor. It is probably going into a loop due to a circular Object reference. The AbstractVisitor class has a built in solution to this problem by turning off the allowRevisit flag.

Here is your visitor code with the allowRevisit set to false:

package be.asist.birep.decompile;

import java.util.HashSet;
import java.util.Set;

import org.eclipse.edt.mof.egl.Element;
import org.eclipse.edt.mof.egl.Function;
import org.eclipse.edt.mof.egl.Program;
import org.eclipse.edt.mof.impl.AbstractVisitor;

public class SubPartParser extends AbstractVisitor{
    HashSet<Element> subParts = new HashSet<Element>();
    boolean visitResultValue = true;

    public SubPartParser() {
        disallowRevisit();     //do not revisit so we dont go into a loop
    }

    public Set<Element> getSubPartsForPart(Element part) {
        try {
            subParts = new HashSet<Element>();
            part.accept(this);
            return subParts;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }


    public boolean visit(Function obj) {
        subParts.add((Element)obj);
        return true;
    }
    public boolean visit(Program obj) {
        subParts.add((Element)obj);
        return true;
    }        
}
Comment 3 Lisa Lasher CLA 2012-04-04 22:26:16 EDT
Please verify that this problem is fixed in EDT 0.7 GA or any 0.8 build, and close the bug.  If you still see a problem, you can reopen the bug with additional information.
Comment 4 Bart Van Campenhout CLA 2012-04-09 09:33:05 EDT
Resolved