views:

71

answers:

4

I have this constructor;

public UmlDiagramEntity(ReportElement reportElement, int pageIndex, Controller controller) {
    super(reportElement.getX1(), reportElement.getY1(), reportElement.getX2(), reportElement.getY2());
    setLayout(null);

    this.pageIndex = pageIndex;
    this.controller = controller;
    reportElements = reportElement.getInternalReportElements();
    components = new ArrayList<AbstractEntity>();
    changedComponentIndex = -1;

    PageListener p = new PageListener();
    this.addMouseMotionListener(p);
    this.addMouseListener(p);

    setPage();
}

And I have an update method in the same class;

   @Override
    public void update(ReportElement reportElement) {
        if (changedComponentIndex == -1) {
            super.update(reportElement);
        } else {
            reportElements = reportElement.getInternalReportElements();
            if (components.size() == reportElements.size()) {
                if (!isCommitted) {
                    if (reportElement.getType() == ReportElementType.UmlRelation) {
                        if (checkInvolvementAndSet(changedComponentIndex)) {
                            anchorEntity(changedComponentIndex);
                        } else {
                            resistChanges(changedComponentIndex);
                        }
                        return;
                    }
                }
..................goes on

When I follow the flow from the debugger, I see that when update is called, somewhere in the method, the program goes into the constructor and executes it all over again (super, pageIndex, etc.). Why does it go to the constructor :D I didn't tell it to go there.

I can make a deeper analysis and see where it goes to the constructor if you want. By the way, changedComponentIndex is a static variable.

+1  A: 

I would find it far more probable that you are seeing it construct two different objects. You'd have to provide more information like a stack trace; here you haven't even shown the constructor being invoked!

Sean Owen
A: 

The behaviour you describe is pretty much impossible. Either your code is different from what you've shown or you're not debugging the code you think you're debugging. Without complete code that we can run, that's all we can say.

Michael Borgwardt
yeah, there is something wrong with my method calls from within update. For a minute there I thought the 'impossible' had happened.
Halo
A: 

Are you sure that update is not called indirectly from within the constructor, which would result in a breakpoint in update getting triggered.

Try setting a breakpoint at the start of the constructor and at the end, then one in update. When you hit the first constructor breakpoint, hit 'continue' and see which breakpoint gets triggered next.

ptomli
A: 

Is this multi-threaded? Is it possible that the constructor for a different instance created on another thread is being called?

Davy8
no no, thanks, i thought an impossible thing was happening, so I kinda freaked out.
Halo