Tuesday 30 March 2010

March 30th, project submitted...

... ahhhhh. Time for a nice big Cohiba :-D

Sunday 7 March 2010

Lesson of the day: cloning and inner classes.

Today I spent a while tracking down a bug I had introduced into the Findbugs code. It concerned filtering bugs in the GUI. If you had one analysis opened, then opened a second one, and tried to filter a bug, the bugs displayed would revert to ones from the first analysis.

Long story short, the bug was in this code:


protected BugTreeModel(BugTreeModel other) {
this.root = new BugAspects(other.root);
this.sorter = other.sorter;
this.bugSet = new BugSet(other.bugSet);
this.bugTreeFilterListener = other.bugTreeFilterListener;
this.tree = other.tree;
this.filterActivity = other.filterActivity;
this.setTreeHolder(other.treeSwapper);
}



Pretty innocuous clone constructor, you might think. The problem is with the bugTreeFilterListener field. This field is an instance of an inner class. When that field gets copied over, so to does the implicit reference the inner class has to its outer class. This meant when the bugTreeFilterListener was calling methods to the outer class (which holds the collection of bugs displayed), it was calling it on the old, source-of-the-clone, instance. Reconstructing the field solved the problem.

Mental note to self: don't copy references of inner classes across instances of outer classes.