Program: 11065
Project: 11065
Buggy source:
public void addLayer(ILayerDefinition layer,List<IData> parents){
  INode layerNode=LayerNode.createFromLayerDefinition(layer);
  List<INode> expandPath=new ArrayList<INode>();
  INode currentParent=getRoot();
  IData directParent=null;
  if (parents != null) {
    if (!parents.isEmpty()) {
      directParent=parents.get(parents.size() - 1);
    }
    int startIndex=0;
    for (int i=parents.size() - 1; i >= 0; i--) {
      if (parents.get(i).isBase()) {
        startIndex=i;
        break;
      }
    }
    for (int i=startIndex; i < parents.size(); i++) {
      IData data=parents.get(i);
      INode node=null;
      for (int j=0; j < currentParent.getChildCount(); j++) {
        INode child=currentParent.getChild(j);
        if (sameFolder(data,child)) {
          node=child;
          break;
        }
      }
      if (node == null) {
        node=new FolderNode(data.getName(),data.getInfoURL(),data.getIconURL(),true);
        insertNodeInto(node,currentParent,currentParent.getChildCount(),false);
      }
      expandPath.add(currentParent);
      currentParent=node;
    }
  }
  expandPath.add(currentParent);
  expandPath.add(layerNode);
  int index=currentParent.getChildCount();
  if (directParent != null && directParent instanceof IDataset) {
    IDataset dataset=(IDataset)directParent;
    int insertionIndex=findInsertionIndex(layer,dataset,currentParent);
    if (insertionIndex >= 0) {
      index=insertionIndex;
    }
  }
  insertNodeInto(layerNode,currentParent,index,true);
  TreePath expand=new TreePath(expandPath.toArray());
  tree.getUI().relayout(expand);
  tree.scrollPathToVisible(expand);
}

Fixed version (ground truth):
public void addLayer(ILayerDefinition layer,List<IData> parents){
  INode layerNode=LayerNode.createFromLayerDefinition(layer);
  List<INode> expandPath=new ArrayList<INode>();
  INode currentParent=getRoot();
  IData directParent=null;
  if (parents != null) {
    if (!parents.isEmpty()) {
      directParent=parents.get(parents.size() - 1);
    }
    int startIndex=0;
    for (int i=parents.size() - 1; i >= 0; i--) {
      if (parents.get(i).isBase()) {
        startIndex=i;
        break;
      }
    }
    for (int i=startIndex; i < parents.size(); i++) {
      IData data=parents.get(i);
      INode node=null;
      for (int j=0; j < currentParent.getChildCount(); j++) {
        INode child=currentParent.getChild(j);
        if (sameFolder(data,child)) {
          node=child;
          break;
        }
      }
      if (node == null) {
        node=new FolderNode(data.getName(),data.getInfoURL(),data.getIconURL(),true);
        insertNodeInto(node,currentParent,currentParent.getChildCount(),false);
      }
      expandPath.add(currentParent);
      currentParent=node;
    }
  }
  expandPath.add(currentParent);
  expandPath.add(layerNode);
  int index=currentParent.getChildCount();
  if (directParent != null && directParent instanceof IDataset) {
    IDataset dataset=(IDataset)directParent;
    int insertionIndex=findInsertionIndex(layer,dataset,currentParent);
    if (insertionIndex >= 0) {
      index=insertionIndex;
    }
  }
  insertNodeInto(layerNode,currentParent,index,true);
  final TreePath expand=new TreePath(expandPath.toArray());
  SwingUtil.invokeLaterTaskOnEDT(new Runnable(){
    @Override public void run(){
      tree.getUI().relayout(expand);
      tree.scrollPathToVisible(expand);
    }
  }
);
}