Program: 67767
Project: 67767
Buggy source:
private void populateTimeMirror() throws IOException {
  MemberTreeNode parent;
  MemberTreeNode child;
  Object[] preValue=new Object[rs.getLevelCount()];
  Object[] currValue=new Object[rs.getLevelCount()];
  final int sortType=this.getSortTypeOnMirroredLevel(this.mirrorLevel);
  if (sortType != IDimensionSortDefn.SORT_UNDEFINED) {
    noBreakHierarchyKeyMap=new TreeMap(new Comparator(){
      public int compare(      final Object arg0,      final Object arg1){
        if (sortType == IDimensionSortDefn.SORT_ASC)         return ((Comparable)arg0).compareTo(arg1);
 else         return ((Comparable)arg0).compareTo(arg1) * -1;
      }
    }
);
  }
 else {
    noBreakHierarchyKeyMap=new HashMap();
  }
  for (int i=0; i < rs.length(); i++) {
    rs.seek(i);
    parent=this.rootNode;
    for (int j=0; j < rs.getLevelCount(); j++) {
      currValue[j]=rs.getLevelKeyValue(j)[0];
    }
    for (int j=0; j < this.mirrorLevel; j++) {
      if (!isEqualObject(preValue[j],currValue[j])) {
        Member member=new Member();
        member.setKeyValues(new Object[]{currValue[j]});
        member.setAttributes(rs.getLevelAttributesValue(j));
        child=new MemberTreeNode(member);
        parent.insertNode(child);
        child.parentNode=parent;
        parent=child;
      }
 else {
        if (parent.childNodesList.size() > 0)         parent=(MemberTreeNode)parent.childNodesList.get(parent.childNodesList.size() - 1);
 else {
          Member member=new Member();
          member.setKeyValues(new Object[]{currValue[j]});
          member.setAttributes(rs.getLevelAttributesValue(j));
          child=new MemberTreeNode(member);
          parent.insertNode(child);
          child.parentNode=parent;
          parent=child;
        }
      }
    }
    Member mirrorMember=new Member();
    mirrorMember.setKeyValues(new Object[]{currValue[this.mirrorLevel]});
    mirrorMember.setAttributes(rs.getLevelAttributesValue(this.mirrorLevel));
    if (noBreakHierarchyKeyMap.containsKey(mirrorMember)) {
      MemberTreeNode node=(MemberTreeNode)noBreakHierarchyKeyMap.get(mirrorMember);
      for (int j=this.mirrorLevel + 1; j < this.rs.getLevelCount(); j++) {
        Member member=new Member();
        member.setKeyValues(new Object[]{currValue[j]});
        member.setAttributes(rs.getLevelAttributesValue(j));
        if (!node.containsChild(member)) {
          if (TimeMemberUtil.isTimeMirror(rs,j)) {
            break;
          }
 else {
            MemberTreeNode childNode=new MemberTreeNode(member);
            node.insertNode(childNode);
            childNode.parentNode=node;
            node=childNode;
          }
        }
 else {
          node=node.getChild(member);
        }
      }
    }
 else {
      MemberTreeNode parentNode=null;
      for (int j=this.mirrorLevel; j < this.rs.getLevelCount(); j++) {
        if (TimeMemberUtil.isTimeMirror(rs,j)) {
          MemberTreeNode[] nodes=TimeMemberUtil.getDateTimeNodes(rs.getAttributeNames(),rs.getLevelAttribute(j,0),j);
          for (int k=0; k < nodes.length; k++) {
            if (parentNode == null) {
              noBreakHierarchyKeyMap.put(nodes[k].key,nodes[k]);
            }
 else             parentNode.insertNode(nodes[k]);
            nodes[k].parentNode=parentNode;
          }
          break;
        }
 else {
          if (parentNode == null) {
            Member member=new Member();
            member.setKeyValues(new Object[]{currValue[j]});
            member.setAttributes(rs.getLevelAttributesValue(j));
            parentNode=new MemberTreeNode(member);
            noBreakHierarchyKeyMap.put(mirrorMember,parentNode);
          }
 else {
            Member member=new Member();
            member.setKeyValues(new Object[]{currValue[j]});
            member.setAttributes(rs.getLevelAttributesValue(j));
            MemberTreeNode childNode=new MemberTreeNode(member);
            parentNode.insertNode(childNode);
            childNode.parentNode=parentNode;
            parentNode=childNode;
          }
        }
      }
    }
    for (int k=0; k < rs.getLevelCount(); k++) {
      preValue[k]=currValue[k];
    }
  }
  int level=mirrorLevel + 1;
  List nodeList1=new ArrayList();
  nodeList1.addAll(noBreakHierarchyKeyMap.values());
  for (int k=mirrorLevel + 1; k < rs.getLevelCount(); k++) {
    final int childSortType=this.getSortTypeOnMirroredLevel(k);
    List nodeList2=new ArrayList();
    if (sortType != IDimensionSortDefn.SORT_UNDEFINED) {
      while (k > level) {
        for (int j=0; j < nodeList1.size(); j++) {
          nodeList2.addAll(((MemberTreeNode)nodeList1.get(j)).childNodesList);
        }
        nodeList1.clear();
        nodeList1.addAll(nodeList2);
        nodeList2.clear();
        level++;
      }
      for (int j=0; j < nodeList1.size(); j++) {
        MemberTreeNode node=(MemberTreeNode)nodeList1.get(j);
        Collections.sort(node.childNodesList,new Comparator(){
          public int compare(          final Object arg0,          final Object arg1){
            if (childSortType == IDimensionSortDefn.SORT_ASC)             return ((Comparable)((MemberTreeNode)arg0).key).compareTo(((MemberTreeNode)arg1).key);
 else             return ((Comparable)((MemberTreeNode)arg0).key).compareTo(((MemberTreeNode)arg1).key) * -1;
          }
        }
);
      }
    }
  }
}

Fixed version (ground truth):
private void populateTimeMirror() throws IOException {
  MemberTreeNode parent;
  MemberTreeNode child;
  Object[] preValue=new Object[rs.getLevelCount()];
  Object[] currValue=new Object[rs.getLevelCount()];
  final int sortType=this.getSortTypeOnMirroredLevel(this.mirrorLevel);
  if (sortType != IDimensionSortDefn.SORT_UNDEFINED) {
    noBreakHierarchyKeyMap=new TreeMap(new Comparator(){
      public int compare(      final Object arg0,      final Object arg1){
        if (sortType == IDimensionSortDefn.SORT_ASC)         return ((Comparable)arg0).compareTo(arg1);
 else         return ((Comparable)arg0).compareTo(arg1) * -1;
      }
    }
);
  }
 else {
    noBreakHierarchyKeyMap=new HashMap();
  }
  for (int i=0; i < rs.length(); i++) {
    rs.seek(i);
    parent=this.rootNode;
    for (int j=0; j < rs.getLevelCount(); j++) {
      currValue[j]=rs.getLevelKeyValue(j)[0];
    }
    for (int j=0; j < this.mirrorLevel; j++) {
      if (!isEqualObject(preValue[j],currValue[j])) {
        Member member=new Member();
        member.setKeyValues(new Object[]{currValue[j]});
        member.setAttributes(rs.getLevelAttributesValue(j));
        child=new MemberTreeNode(member);
        parent.insertNode(child);
        child.parentNode=parent;
        parent=child;
      }
 else {
        if (parent.childNodesList.size() > 0)         parent=(MemberTreeNode)parent.childNodesList.get(parent.childNodesList.size() - 1);
 else {
          Member member=new Member();
          member.setKeyValues(new Object[]{currValue[j]});
          member.setAttributes(rs.getLevelAttributesValue(j));
          child=new MemberTreeNode(member);
          parent.insertNode(child);
          child.parentNode=parent;
          parent=child;
        }
      }
    }
    Member mirrorMember=new Member();
    mirrorMember.setKeyValues(new Object[]{currValue[this.mirrorLevel]});
    mirrorMember.setAttributes(rs.getLevelAttributesValue(this.mirrorLevel));
    if (noBreakHierarchyKeyMap.containsKey(mirrorMember)) {
      MemberTreeNode node=(MemberTreeNode)noBreakHierarchyKeyMap.get(mirrorMember);
      for (int j=this.mirrorLevel + 1; j < this.rs.getLevelCount(); j++) {
        Member member=new Member();
        member.setKeyValues(new Object[]{currValue[j]});
        member.setAttributes(rs.getLevelAttributesValue(j));
        if (!node.containsChild(member)) {
          if (TimeMemberUtil.isTimeMirror(rs,j,service)) {
            break;
          }
 else {
            MemberTreeNode childNode=new MemberTreeNode(member);
            node.insertNode(childNode);
            childNode.parentNode=node;
            node=childNode;
          }
        }
 else {
          node=node.getChild(member);
        }
      }
    }
 else {
      MemberTreeNode parentNode=null;
      for (int j=this.mirrorLevel; j < this.rs.getLevelCount(); j++) {
        if (TimeMemberUtil.isTimeMirror(rs,j,service)) {
          MemberTreeNode[] nodes=TimeMemberUtil.getDateTimeNodes(rs.getAllLevels(),rs.getLevelAttribute(j,0),j,service);
          for (int k=0; k < nodes.length; k++) {
            if (parentNode == null) {
              noBreakHierarchyKeyMap.put(nodes[k].key,nodes[k]);
            }
 else             parentNode.insertNode(nodes[k]);
            nodes[k].parentNode=parentNode;
          }
          break;
        }
 else {
          if (parentNode == null) {
            Member member=new Member();
            member.setKeyValues(new Object[]{currValue[j]});
            member.setAttributes(rs.getLevelAttributesValue(j));
            parentNode=new MemberTreeNode(member);
            noBreakHierarchyKeyMap.put(mirrorMember,parentNode);
          }
 else {
            Member member=new Member();
            member.setKeyValues(new Object[]{currValue[j]});
            member.setAttributes(rs.getLevelAttributesValue(j));
            MemberTreeNode childNode=new MemberTreeNode(member);
            parentNode.insertNode(childNode);
            childNode.parentNode=parentNode;
            parentNode=childNode;
          }
        }
      }
    }
    for (int k=0; k < rs.getLevelCount(); k++) {
      preValue[k]=currValue[k];
    }
  }
  int level=mirrorLevel + 1;
  List nodeList1=new ArrayList();
  nodeList1.addAll(noBreakHierarchyKeyMap.values());
  for (int k=mirrorLevel + 1; k < rs.getLevelCount(); k++) {
    final int childSortType=this.getSortTypeOnMirroredLevel(k);
    List nodeList2=new ArrayList();
    if (sortType != IDimensionSortDefn.SORT_UNDEFINED) {
      while (k > level) {
        for (int j=0; j < nodeList1.size(); j++) {
          nodeList2.addAll(((MemberTreeNode)nodeList1.get(j)).childNodesList);
        }
        nodeList1.clear();
        nodeList1.addAll(nodeList2);
        nodeList2.clear();
        level++;
      }
      for (int j=0; j < nodeList1.size(); j++) {
        MemberTreeNode node=(MemberTreeNode)nodeList1.get(j);
        Collections.sort(node.childNodesList,new Comparator(){
          public int compare(          final Object arg0,          final Object arg1){
            if (childSortType == IDimensionSortDefn.SORT_ASC)             return ((Comparable)((MemberTreeNode)arg0).key).compareTo(((MemberTreeNode)arg1).key);
 else             return ((Comparable)((MemberTreeNode)arg0).key).compareTo(((MemberTreeNode)arg1).key) * -1;
          }
        }
);
      }
    }
  }
}