Program: 188555
Project: 188555
Buggy source:
private String createAncestors(SIP sip,IndexService index,ModelService model,String forcedParent) throws GenericException, RequestNotValidException, AuthorizationDeniedException, NotFoundException, AlreadyExistsException, ValidationException {
  List<String> ancestors=new ArrayList<>(sip.getAncestors());
  if (ancestors.isEmpty())   return null;
  Collections.reverse(ancestors);
  String parent=StringUtils.isBlank(forcedParent) ? null : forcedParent;
  for (  String ancestor : ancestors) {
    try {
      Filter ancestorFilter=new Filter(new SimpleFilterParameter(RodaConstants.INGEST_SIP_ID,ancestor));
      if (!StringUtils.isBlank(forcedParent)) {
        ancestorFilter.add(new SimpleFilterParameter(RodaConstants.AIP_ANCESTORS,forcedParent));
      }
      IndexResult<IndexedAIP> result=index.find(IndexedAIP.class,ancestorFilter,Sorter.NONE,new Sublist(0,1));
      if (result.getTotalCount() >= 1) {
        IndexedAIP indexedAIP=result.getResults().get(0);
        parent=indexedAIP.getId();
      }
 else       throw new NotFoundException();
    }
 catch (    NotFoundException e) {
      Job currentJob=PluginHelper.getJob(this,index);
      if (currentJob == null) {
        throw new GenericException("String_Node_Str");
      }
      String username=currentJob.getUsername();
      Permissions permissions=new Permissions();
      permissions.setUserPermissions(username,new HashSet<>(Arrays.asList(Permissions.PermissionType.CREATE,Permissions.PermissionType.READ,Permissions.PermissionType.UPDATE,Permissions.PermissionType.DELETE,Permissions.PermissionType.GRANT)));
      boolean isGhost=true;
      AIP ghostAIP=model.createAIP(parent,"String_Node_Str",permissions,true,ancestor,isGhost,username);
      parent=ghostAIP.getId();
    }
  }
  return parent;
}

Fixed version (ground truth):
private String createAncestors(SIP sip,IndexService index,ModelService model,String forcedParent) throws GenericException, RequestNotValidException, AuthorizationDeniedException, NotFoundException, AlreadyExistsException, ValidationException {
  List<String> ancestors=new ArrayList<>(sip.getAncestors());
  if (ancestors.isEmpty())   return null;
  Collections.reverse(ancestors);
  String parent=StringUtils.isBlank(forcedParent) ? null : forcedParent;
  for (  String ancestor : ancestors) {
    try {
      Filter ancestorFilter=new Filter(new SimpleFilterParameter(RodaConstants.INGEST_SIP_ID,ancestor));
      if (!StringUtils.isBlank(forcedParent)) {
        ancestorFilter.add(new SimpleFilterParameter(RodaConstants.AIP_ANCESTORS,forcedParent));
      }
      IndexResult<IndexedAIP> result=index.find(IndexedAIP.class,ancestorFilter,Sorter.NONE,new Sublist(0,1));
      if (result.getTotalCount() >= 1) {
        IndexedAIP indexedAIP=result.getResults().get(0);
        parent=indexedAIP.getId();
      }
 else {
        IndexedAIP aip=index.retrieve(IndexedAIP.class,ancestor);
        parent=aip.getId();
      }
    }
 catch (    NotFoundException e) {
      Job currentJob=PluginHelper.getJob(this,index);
      if (currentJob == null) {
        throw new GenericException("String_Node_Str");
      }
      String username=currentJob.getUsername();
      Permissions permissions=new Permissions();
      permissions.setUserPermissions(username,new HashSet<>(Arrays.asList(Permissions.PermissionType.CREATE,Permissions.PermissionType.READ,Permissions.PermissionType.UPDATE,Permissions.PermissionType.DELETE,Permissions.PermissionType.GRANT)));
      boolean isGhost=true;
      AIP ghostAIP=model.createAIP(parent,"String_Node_Str",permissions,true,ancestor,isGhost,username);
      parent=ghostAIP.getId();
    }
  }
  return parent;
}