Program: 143622
Project: 143622
Buggy source:
/** 
 * @param flattenedSolution
 * @param form
 * @throws RepositoryException
 */
private void fill(){
  List<Form> allForms=flattenedSolution.getFormHierarchy(form);
  copyPropertiesMap(form.getPropertiesMap(),false);
  Set<String> methods=new HashSet<String>(64);
  Set<String> variables=new HashSet<String>(64);
  List<Integer> existingIDs=new ArrayList<Integer>();
  for (  Form f : allForms) {
    for (    IPersist ip : f.getAllObjectsAsList()) {
      Integer extendsID=(ip instanceof ISupportExtendsID) ? new Integer(((ISupportExtendsID)ip).getExtendsID()) : Integer.valueOf(-1);
      if (!existingIDs.contains(new Integer(ip.getID())) && !existingIDs.contains(extendsID)) {
        if (ip instanceof ISupportExtendsID && PersistHelper.isOverrideOrphanElement((ISupportExtendsID)ip)) {
          continue;
        }
        boolean addScriptMethod=(ip instanceof ScriptMethod && methods.add(((ScriptMethod)ip).getName()));
        boolean addScriptVariable=(ip instanceof ScriptVariable && variables.add(((ScriptVariable)ip).getName()));
        boolean addOtherElement=(!(ip instanceof Part) && !(ip instanceof ScriptMethod) && !(ip instanceof ScriptVariable));
        if (addScriptVariable || addScriptMethod || addOtherElement) {
          if (ip instanceof TabPanel) {
            internalAddChild(new FlattenedTabPanel((TabPanel)ip));
          }
 else           if (ip instanceof Portal) {
            internalAddChild(new FlattenedPortal((Portal)ip));
          }
 else {
            internalAddChild(ip);
          }
        }
      }
      if (ip instanceof ISupportExtendsID && PersistHelper.isOverrideElement((ISupportExtendsID)ip) && !existingIDs.contains(extendsID)) {
        existingIDs.add(extendsID);
      }
    }
  }
  Part prevPart=null;
  Collections.reverse(allForms);
  for (  Form f : allForms) {
    Iterator<Part> parts=f.getParts();
    while (parts.hasNext()) {
      Part part=parts.next();
      if (PersistHelper.isOverrideElement(part)) {
        Part parentPart=null;
        Iterator<Part> it=getParts();
        while (it.hasNext()) {
          Part temp=it.next();
          if (temp.getID() == part.getExtendsID() || temp.getExtendsID() == part.getExtendsID()) {
            parentPart=temp;
            break;
          }
        }
        if (parentPart != null) {
          internalAddChild(part);
          internalRemoveChild(parentPart);
        }
      }
 else {
        internalAddChild(part);
        prevPart=part;
      }
    }
  }
  setSize(checkParts(getParts(),getSize()));
}

Fixed version (ground truth):
/** 
 * @param flattenedSolution
 * @param form
 * @throws RepositoryException
 */
private void fill(){
  List<Form> allForms=flattenedSolution.getFormHierarchy(form);
  copyPropertiesMap(form.getPropertiesMap(),false);
  Set<String> methods=new HashSet<String>(64);
  Set<String> variables=new HashSet<String>(64);
  List<Integer> existingIDs=new ArrayList<Integer>();
  for (  Form f : allForms) {
    for (    IPersist ip : f.getAllObjectsAsList()) {
      Integer extendsID=(ip instanceof ISupportExtendsID) ? new Integer(((ISupportExtendsID)ip).getExtendsID()) : Integer.valueOf(-1);
      if (!existingIDs.contains(new Integer(ip.getID())) && !existingIDs.contains(extendsID)) {
        if (ip instanceof ISupportExtendsID && PersistHelper.isOverrideOrphanElement((ISupportExtendsID)ip)) {
          continue;
        }
        boolean addScriptMethod=(ip instanceof ScriptMethod && methods.add(((ScriptMethod)ip).getName()));
        boolean addScriptVariable=(ip instanceof ScriptVariable && variables.add(((ScriptVariable)ip).getName()));
        boolean addOtherElement=(!(ip instanceof Part) && !(ip instanceof ScriptMethod) && !(ip instanceof ScriptVariable));
        if (addScriptVariable || addScriptMethod || addOtherElement) {
          if (ip instanceof TabPanel) {
            internalAddChild(new FlattenedTabPanel((TabPanel)ip));
          }
 else           if (ip instanceof Portal) {
            internalAddChild(new FlattenedPortal((Portal)ip));
          }
 else {
            internalAddChild(ip);
          }
        }
      }
      if (ip instanceof ISupportExtendsID && PersistHelper.isOverrideElement((ISupportExtendsID)ip) && !existingIDs.contains(extendsID)) {
        existingIDs.add(extendsID);
      }
    }
  }
  Part prevPart=null;
  Collections.reverse(allForms);
  for (  Form f : allForms) {
    Iterator<Part> parts=f.getParts();
    while (parts.hasNext()) {
      Part part=parts.next();
      if (PersistHelper.isOverrideElement(part)) {
        Part parentPart=null;
        Iterator<Part> it=getParts();
        while (it.hasNext()) {
          Part temp=it.next();
          if (temp.getID() == part.getExtendsID() || temp.getExtendsID() == part.getExtendsID()) {
            parentPart=temp;
            break;
          }
        }
        if (parentPart != null) {
          internalAddChild(part);
          internalRemoveChild(parentPart);
        }
      }
 else {
        if (prevPart == null || prevPart.getPartType() < part.getPartType() || (prevPart.getPartType() == part.getPartType() && part.canBeMoved())) {
          internalAddChild(part);
          prevPart=part;
        }
      }
    }
  }
  setSize(checkParts(getParts(),getSize()));
}