Program: 143769
Project: 143769
Buggy source:
public Object findDuplicate(String nameToCheck,int skip_element_id,ValidatorSearchContext searchContext) throws RepositoryException {
  if (solutionRoot == null) {
    return null;
  }
  if (nameToCheck == null) {
    Debug.error("String_Node_Str" + skip_element_id);
    return null;
  }
  if (searchContext == null) {
    return null;
  }
  if ((searchContext.getType() == IRepository.SCRIPTVARIABLES || searchContext.getType() == IRepository.METHODS) && !(searchContext.getObject() instanceof Form)) {
    Iterator<ScriptVariable> vars=solutionRoot.getScriptVariables(false);
    while (vars.hasNext()) {
      ScriptVariable sgv=vars.next();
      if (nameToCheck.equals(sgv.getName()) && sgv.getID() != skip_element_id) {
        return sgv;
      }
    }
    Iterator<ScriptMethod> scripts=solutionRoot.getScriptMethods(false);
    while (scripts.hasNext()) {
      ScriptMethod sm=scripts.next();
      if (nameToCheck.equals(sm.getName()) && sm.getID() != skip_element_id) {
        return sm;
      }
    }
  }
  if (searchContext.getType() == IRepository.FORMS) {
    Iterator<Form> it=solutionRoot.getForms(false);
    while (it.hasNext()) {
      Form form=it.next();
      if (nameToCheck.equalsIgnoreCase(form.getName()) && form.getID() != skip_element_id) {
        return form;
      }
    }
  }
  if (searchContext.getObject() instanceof Form && searchContext.getType() != IRepository.ELEMENTS && searchContext.getType() != IRepository.FORMS) {
    Object obj=testRelations(nameToCheck,skip_element_id);
    if (obj != null)     return obj;
    obj=testFormScripts((Form)searchContext.getObject(),nameToCheck,skip_element_id);
    if (obj != null)     return obj;
    obj=testFormVars((Form)searchContext.getObject(),nameToCheck,skip_element_id);
    if (obj != null)     return obj;
    obj=testTableProviders(((Form)searchContext.getObject()).getTable(),nameToCheck,skip_element_id,false,false);
    if (obj != null)     return obj;
  }
  if (searchContext.getObject() instanceof Table) {
    Object obj=testRelations(nameToCheck,skip_element_id);
    if (obj != null)     return obj;
    Iterator<Form> it=solutionRoot.getForms((Table)searchContext.getObject(),false);
    while (it.hasNext()) {
      Form f=it.next();
      obj=testFormScripts(f,nameToCheck,skip_element_id);
      if (obj != null)       return obj;
    }
    obj=testTableProviders((Table)searchContext.getObject(),nameToCheck,skip_element_id,searchContext.getType() == IRepository.COLUMNS,searchContext.getType() == IRepository.SCRIPTCALCULATIONS);
    if (obj != null)     return obj;
  }
  if (searchContext.getType() == IRepository.RELATIONS) {
    Object obj=testRelations(nameToCheck,skip_element_id);
    if (obj != null)     return obj;
    Iterator<Form> it=solutionRoot.getForms(false);
    while (it.hasNext()) {
      obj=testFormScripts(it.next(),nameToCheck,skip_element_id);
      if (obj != null)       return obj;
    }
  }
  if (searchContext.getType() == IRepository.VALUELISTS) {
    Iterator<ValueList> it=solutionRoot.getValueLists(false);
    while (it.hasNext()) {
      ValueList vl=it.next();
      if (nameToCheck.equalsIgnoreCase(vl.getName()) && vl.getID() != skip_element_id) {
        return vl;
      }
    }
  }
  if (searchContext.getType() == IRepository.MEDIA) {
    Iterator<Media> it=solutionRoot.getMedias(false);
    while (it.hasNext()) {
      Media media=it.next();
      if (nameToCheck.equalsIgnoreCase(media.getName()) && media.getID() != skip_element_id) {
        return media;
      }
    }
  }
  if (searchContext.getType() == IRepository.ELEMENTS) {
    Iterator<IPersist> iterator=((ISupportChilds)searchContext.getObject()).getAllObjects();
    while (iterator.hasNext()) {
      IPersist persist=iterator.next();
      if (persist instanceof IFormElement && persist.getID() != skip_element_id) {
        if (persist instanceof ISupportName && nameToCheck.equalsIgnoreCase(((ISupportName)persist).getName())) {
          return persist;
        }
        if (nameToCheck.equalsIgnoreCase(((IFormElement)persist).getGroupID())) {
          return new FormElementGroup(((IFormElement)persist).getGroupID(),solutionRoot,(Form)persist.getParent());
        }
      }
    }
  }
  if (searchContext.getType() == IRepository.TABS) {
    Iterator<IPersist> iterator=((ISupportChilds)searchContext.getObject()).getAllObjects();
    while (iterator.hasNext()) {
      IPersist persist=iterator.next();
      if (persist instanceof Tab && nameToCheck.equalsIgnoreCase(((Tab)persist).getName()) && persist.getID() != skip_element_id) {
        return persist;
      }
    }
  }
  return null;
}

Fixed version (ground truth):
public Object findDuplicate(String nameToCheck,int skip_element_id,ValidatorSearchContext searchContext) throws RepositoryException {
  if (solutionRoot == null) {
    return null;
  }
  if (nameToCheck == null) {
    Debug.error("String_Node_Str" + skip_element_id);
    return null;
  }
  if (searchContext == null) {
    return null;
  }
  if (searchContext.getType() == IRepository.METHODS && searchContext.getObject() instanceof TableNode) {
    TableNode tn=(TableNode)searchContext.getObject();
    Table table=tn.getTable();
    Iterator<ScriptCalculation> calculations=solutionRoot.getScriptCalculations(table,false);
    while (calculations.hasNext()) {
      ScriptCalculation sc=calculations.next();
      if (nameToCheck.equals(sc.getName()) && sc.getID() != skip_element_id) {
        return sc;
      }
    }
  }
  if ((searchContext.getType() == IRepository.SCRIPTVARIABLES || searchContext.getType() == IRepository.METHODS) && !(searchContext.getObject() instanceof Form)) {
    Iterator<ScriptVariable> vars=solutionRoot.getScriptVariables(false);
    while (vars.hasNext()) {
      ScriptVariable sgv=vars.next();
      if (nameToCheck.equals(sgv.getName()) && sgv.getID() != skip_element_id) {
        return sgv;
      }
    }
    Iterator<ScriptMethod> scripts=solutionRoot.getScriptMethods(false);
    while (scripts.hasNext()) {
      ScriptMethod sm=scripts.next();
      if (nameToCheck.equals(sm.getName()) && sm.getID() != skip_element_id) {
        return sm;
      }
    }
  }
  if (searchContext.getType() == IRepository.FORMS) {
    Iterator<Form> it=solutionRoot.getForms(false);
    while (it.hasNext()) {
      Form form=it.next();
      if (nameToCheck.equalsIgnoreCase(form.getName()) && form.getID() != skip_element_id) {
        return form;
      }
    }
  }
  if (searchContext.getObject() instanceof Form && searchContext.getType() != IRepository.ELEMENTS && searchContext.getType() != IRepository.FORMS) {
    Object obj=testRelations(nameToCheck,skip_element_id);
    if (obj != null)     return obj;
    obj=testFormScripts((Form)searchContext.getObject(),nameToCheck,skip_element_id);
    if (obj != null)     return obj;
    obj=testFormVars((Form)searchContext.getObject(),nameToCheck,skip_element_id);
    if (obj != null)     return obj;
    obj=testTableProviders(((Form)searchContext.getObject()).getTable(),nameToCheck,skip_element_id,false,false);
    if (obj != null)     return obj;
  }
  if (searchContext.getObject() instanceof Table) {
    Object obj=testRelations(nameToCheck,skip_element_id);
    if (obj != null)     return obj;
    Iterator<Form> it=solutionRoot.getForms((Table)searchContext.getObject(),false);
    while (it.hasNext()) {
      Form f=it.next();
      obj=testFormScripts(f,nameToCheck,skip_element_id);
      if (obj != null)       return obj;
    }
    obj=testTableProviders((Table)searchContext.getObject(),nameToCheck,skip_element_id,searchContext.getType() == IRepository.COLUMNS,searchContext.getType() == IRepository.SCRIPTCALCULATIONS);
    if (obj != null)     return obj;
  }
  if (searchContext.getType() == IRepository.RELATIONS) {
    Object obj=testRelations(nameToCheck,skip_element_id);
    if (obj != null)     return obj;
    Iterator<Form> it=solutionRoot.getForms(false);
    while (it.hasNext()) {
      obj=testFormScripts(it.next(),nameToCheck,skip_element_id);
      if (obj != null)       return obj;
    }
  }
  if (searchContext.getType() == IRepository.VALUELISTS) {
    Iterator<ValueList> it=solutionRoot.getValueLists(false);
    while (it.hasNext()) {
      ValueList vl=it.next();
      if (nameToCheck.equalsIgnoreCase(vl.getName()) && vl.getID() != skip_element_id) {
        return vl;
      }
    }
  }
  if (searchContext.getType() == IRepository.MEDIA) {
    Iterator<Media> it=solutionRoot.getMedias(false);
    while (it.hasNext()) {
      Media media=it.next();
      if (nameToCheck.equalsIgnoreCase(media.getName()) && media.getID() != skip_element_id) {
        return media;
      }
    }
  }
  if (searchContext.getType() == IRepository.ELEMENTS) {
    Iterator<IPersist> iterator=((ISupportChilds)searchContext.getObject()).getAllObjects();
    while (iterator.hasNext()) {
      IPersist persist=iterator.next();
      if (persist instanceof IFormElement && persist.getID() != skip_element_id) {
        if (persist instanceof ISupportName && nameToCheck.equalsIgnoreCase(((ISupportName)persist).getName())) {
          return persist;
        }
        if (nameToCheck.equalsIgnoreCase(((IFormElement)persist).getGroupID())) {
          return new FormElementGroup(((IFormElement)persist).getGroupID(),solutionRoot,(Form)persist.getParent());
        }
      }
    }
  }
  if (searchContext.getType() == IRepository.TABS) {
    Iterator<IPersist> iterator=((ISupportChilds)searchContext.getObject()).getAllObjects();
    while (iterator.hasNext()) {
      IPersist persist=iterator.next();
      if (persist instanceof Tab && nameToCheck.equalsIgnoreCase(((Tab)persist).getName()) && persist.getID() != skip_element_id) {
        return persist;
      }
    }
  }
  return null;
}