Program: 188311
Project: 188311
Buggy source:
@Override protected Report executeOnAIP(IndexService index,ModelService model,StorageService storage,Report report,SimpleJobPluginInfo jobPluginInfo,List<AIP> list,Job job) throws PluginException {
  for (  AIP aip : list) {
    LOGGER.debug("String_Node_Str",aip.getId());
    List<String> newRepresentations=new ArrayList<>();
    String newRepresentationID=null;
    boolean notify=true;
    PluginState reportState=PluginState.SUCCESS;
    ValidationReport validationReport=new ValidationReport();
    boolean hasNonPdfFiles=false;
    List<File> alteredFiles=new ArrayList<>();
    List<File> newFiles=new ArrayList<>();
    List<DIPFile> newDIPFiles=new ArrayList<>();
    List<File> unchangedFiles=new ArrayList<>();
    for (    Representation representation : aip.getRepresentations()) {
      newRepresentationID=IdUtils.createUUID();
      PluginState pluginResultState=PluginState.SUCCESS;
      Report reportItem=PluginHelper.initPluginReportItem(this,IdUtils.getRepresentationId(representation),IdUtils.getRepresentationId(representation),Representation.class,AIPState.ACTIVE);
      if (createDIP) {
        reportItem.setOutcomeObjectClass(DIP.class.getName());
      }
      try {
        LOGGER.debug("String_Node_Str",representation);
        boolean recursive=true;
        CloseableIterable<OptionalWithCause<File>> allFiles=model.listFilesUnder(aip.getId(),representation.getId(),recursive);
        for (        OptionalWithCause<File> oFile : allFiles) {
          if (oFile.isPresent()) {
            File file=oFile.get();
            LOGGER.debug("String_Node_Str",file);
            if (!file.isDirectory()) {
              IndexedFile ifile=index.retrieve(IndexedFile.class,IdUtils.getFileId(file),RodaConstants.FILE_FORMAT_FIELDS_TO_RETURN);
              String fileMimetype=ifile.getFileFormat().getMimeType();
              String filePronom=ifile.getFileFormat().getPronom();
              String fileFormat=ifile.getId().substring(ifile.getId().lastIndexOf('.') + 1,ifile.getId().length());
              List<String> applicableTo=getApplicableTo();
              List<String> convertableTo=getConvertableTo();
              Map<String,List<String>> pronomToExtension=getPronomToExtension();
              Map<String,List<String>> mimetypeToExtension=getMimetypeToExtension();
              if (doPluginExecute(fileFormat,filePronom,fileMimetype,applicableTo,convertableTo,pronomToExtension,mimetypeToExtension)) {
                fileFormat=getNewFileFormat(fileFormat,filePronom,fileMimetype,applicableTo,pronomToExtension,mimetypeToExtension);
                StoragePath fileStoragePath=ModelUtils.getFileStoragePath(file);
                DirectResourceAccess directAccess=storage.getDirectAccess(fileStoragePath);
                LOGGER.debug("String_Node_Str",fileFormat,outputFormat,file.getId());
                try {
                  Path pluginResult=Files.createTempFile("String_Node_Str","String_Node_Str" + getOutputFormat());
                  String result=executePlugin(directAccess.getPath(),pluginResult,fileFormat);
                  String newFileId=file.getId().replaceFirst("String_Node_Str","String_Node_Str" + outputFormat);
                  ContentPayload payload=new FSPathContentPayload(pluginResult);
                  if (createDIP) {
                    FileLink fileLink=new FileLink(file.getAipId(),file.getRepresentationId(),file.getPath(),file.getId());
                    List<FileLink> links=new ArrayList<>();
                    links.add(fileLink);
                    DIP dip=new DIP();
                    dip.setId(IdUtils.createUUID());
                    dip.setFileIds(links);
                    dip.setPermissions(aip.getPermissions());
                    dip.setTitle(dipTitle);
                    dip.setDescription(dipDescription);
                    dip.setType(RodaConstants.DIP_TYPE_CONVERSION);
                    dip=model.createDIP(dip,true);
                    newRepresentationID=dip.getId();
                    DIPFile f=model.createDIPFile(newRepresentationID,file.getPath(),newFileId,directAccess.getPath().toFile().length(),payload,notify);
                    newDIPFiles.add(f);
                  }
 else                   if (!newRepresentations.contains(newRepresentationID)) {
                    LOGGER.debug("String_Node_Str",newRepresentationID,aip.getId());
                    boolean original=false;
                    newRepresentations.add(newRepresentationID);
                    String newRepresentationType=representation.getType();
                    model.createRepresentation(aip.getId(),newRepresentationID,original,newRepresentationType,notify);
                    reportItem.setOutcomeObjectId(IdUtils.getRepresentationId(representation.getAipId(),newRepresentationID));
                    File f=model.createFile(aip.getId(),newRepresentationID,file.getPath(),newFileId,payload,notify);
                    newFiles.add(f);
                  }
                  alteredFiles.add(file);
                  IOUtils.closeQuietly(directAccess);
                  Report fileReportItem=PluginHelper.initPluginReportItem(this,file.getId(),File.class,AIPState.ACTIVE);
                  fileReportItem.setPluginState(pluginResultState).setPluginDetails(result);
                  reportItem.addReport(fileReportItem);
                }
 catch (                CommandException e) {
                  pluginResultState=PluginState.PARTIAL_SUCCESS;
                  reportState=pluginResultState;
                  reportItem.setPluginState(pluginResultState).addPluginDetails(e.getMessage() + "String_Node_Str" + e.getOutput()+ "String_Node_Str");
                  LOGGER.debug("String_Node_Str",fileFormat,outputFormat,file.getId(),representation.getId(),aip.getId());
                }
              }
 else {
                unchangedFiles.add(file);
                if (ignoreFiles) {
                  validationReport.addIssue(new ValidationIssue(ModelUtils.getFileStoragePath(file).toString()));
                }
 else {
                  pluginResultState=PluginState.FAILURE;
                  reportState=pluginResultState;
                  hasNonPdfFiles=true;
                }
              }
            }
          }
 else {
            LOGGER.error("String_Node_Str",oFile.getCause());
          }
        }
        IOUtils.closeQuietly(allFiles);
        reportItem.setPluginState(pluginResultState);
        if (reportState.equals(PluginState.SUCCESS)) {
          if (ignoreFiles && !validationReport.getIssues().isEmpty()) {
            reportItem.setHtmlPluginDetails(true).setPluginDetails(validationReport.toHtml(false,false,false,"String_Node_Str"));
          }
        }
        if (hasNonPdfFiles) {
          reportItem.setPluginDetails("String_Node_Str");
        }
        if (!alteredFiles.isEmpty() && !createDIP) {
          createNewFilesOnRepresentation(storage,model,unchangedFiles,newRepresentationID,notify);
        }
      }
 catch (      RuntimeException|NotFoundException|GenericException|RequestNotValidException|AuthorizationDeniedException|IOException|AlreadyExistsException e) {
        LOGGER.error("String_Node_Str" + aip.getId() + "String_Node_Str"+ e.getMessage(),e);
        pluginResultState=PluginState.FAILURE;
        reportState=pluginResultState;
        reportItem.setPluginState(pluginResultState).setPluginDetails(e.getMessage());
      }
 finally {
        report.addReport(reportItem);
        PluginHelper.updatePartialJobReport(this,model,reportItem,true,job);
        if (!createDIP) {
          try {
            Representation rep=model.retrieveRepresentation(aip.getId(),newRepresentationID);
            createPremisSkeletonOnRepresentation(model,aip.getId(),rep);
          }
 catch (          RequestNotValidException|GenericException|NotFoundException|AuthorizationDeniedException|ValidationException|IOException|XmlException e) {
            LOGGER.error("String_Node_Str",e.getMessage());
          }
        }
      }
    }
    try {
      LOGGER.debug("String_Node_Str",aip.getId());
      boolean notifyEvent=false;
      createEvent(model,index,aip.getId(),null,null,null,outputFormat,reportState,alteredFiles,newFiles,notifyEvent);
      model.notifyAipUpdated(aip.getId());
      jobPluginInfo.incrementObjectsProcessed(reportState);
    }
 catch (    PluginException|RequestNotValidException|GenericException|NotFoundException|AuthorizationDeniedException e) {
      LOGGER.debug("String_Node_Str");
    }
  }
  return report;
}

Fixed version (ground truth):
@Override protected Report executeOnAIP(IndexService index,ModelService model,StorageService storage,Report report,SimpleJobPluginInfo jobPluginInfo,List<AIP> list,Job job) throws PluginException {
  for (  AIP aip : list) {
    LOGGER.debug("String_Node_Str",aip.getId());
    List<String> newRepresentations=new ArrayList<>();
    String newRepresentationID=null;
    boolean notify=true;
    PluginState reportState=PluginState.SUCCESS;
    ValidationReport validationReport=new ValidationReport();
    boolean hasNonPdfFiles=false;
    List<File> alteredFiles=new ArrayList<>();
    List<File> newFiles=new ArrayList<>();
    List<DIPFile> newDIPFiles=new ArrayList<>();
    List<File> unchangedFiles=new ArrayList<>();
    for (    Representation representation : aip.getRepresentations()) {
      newRepresentationID=IdUtils.createUUID();
      PluginState pluginResultState=PluginState.SUCCESS;
      Report reportItem=PluginHelper.initPluginReportItem(this,IdUtils.getRepresentationId(representation),IdUtils.getRepresentationId(representation),Representation.class,AIPState.ACTIVE);
      if (createDIP) {
        reportItem.setOutcomeObjectClass(DIP.class.getName());
      }
      try {
        LOGGER.debug("String_Node_Str",representation);
        boolean recursive=true;
        CloseableIterable<OptionalWithCause<File>> allFiles=model.listFilesUnder(aip.getId(),representation.getId(),recursive);
        for (        OptionalWithCause<File> oFile : allFiles) {
          if (oFile.isPresent()) {
            File file=oFile.get();
            LOGGER.debug("String_Node_Str",file);
            if (!file.isDirectory()) {
              IndexedFile ifile=index.retrieve(IndexedFile.class,IdUtils.getFileId(file),RodaConstants.FILE_FORMAT_FIELDS_TO_RETURN);
              String fileMimetype=ifile.getFileFormat().getMimeType();
              String filePronom=ifile.getFileFormat().getPronom();
              String fileFormat=ifile.getId().substring(ifile.getId().lastIndexOf('.') + 1,ifile.getId().length());
              List<String> applicableTo=getApplicableTo();
              List<String> convertableTo=getConvertableTo();
              Map<String,List<String>> pronomToExtension=getPronomToExtension();
              Map<String,List<String>> mimetypeToExtension=getMimetypeToExtension();
              if (doPluginExecute(fileFormat,filePronom,fileMimetype,applicableTo,convertableTo,pronomToExtension,mimetypeToExtension)) {
                fileFormat=getNewFileFormat(fileFormat,filePronom,fileMimetype,applicableTo,pronomToExtension,mimetypeToExtension);
                StoragePath fileStoragePath=ModelUtils.getFileStoragePath(file);
                DirectResourceAccess directAccess=storage.getDirectAccess(fileStoragePath);
                LOGGER.debug("String_Node_Str",fileFormat,outputFormat,file.getId());
                try {
                  Path pluginResult=Files.createTempFile("String_Node_Str","String_Node_Str" + getOutputFormat());
                  String result=executePlugin(directAccess.getPath(),pluginResult,fileFormat);
                  String newFileId=file.getId().replaceFirst("String_Node_Str","String_Node_Str" + outputFormat);
                  ContentPayload payload=new FSPathContentPayload(pluginResult);
                  if (createDIP) {
                    FileLink fileLink=new FileLink(file.getAipId(),file.getRepresentationId(),file.getPath(),file.getId());
                    List<FileLink> links=new ArrayList<>();
                    links.add(fileLink);
                    DIP dip=new DIP();
                    dip.setId(IdUtils.createUUID());
                    dip.setFileIds(links);
                    dip.setPermissions(aip.getPermissions());
                    dip.setTitle(dipTitle);
                    dip.setDescription(dipDescription);
                    dip.setType(RodaConstants.DIP_TYPE_CONVERSION);
                    dip=model.createDIP(dip,true);
                    newRepresentationID=dip.getId();
                    DIPFile f=model.createDIPFile(newRepresentationID,file.getPath(),newFileId,directAccess.getPath().toFile().length(),payload,notify);
                    newDIPFiles.add(f);
                  }
 else {
                    if (!newRepresentations.contains(newRepresentationID)) {
                      LOGGER.debug("String_Node_Str",newRepresentationID,aip.getId());
                      boolean original=false;
                      newRepresentations.add(newRepresentationID);
                      String newRepresentationType=representation.getType();
                      model.createRepresentation(aip.getId(),newRepresentationID,original,newRepresentationType,notify);
                      reportItem.setOutcomeObjectId(IdUtils.getRepresentationId(representation.getAipId(),newRepresentationID));
                    }
                    File f=model.createFile(aip.getId(),newRepresentationID,file.getPath(),newFileId,payload,notify);
                    newFiles.add(f);
                  }
                  alteredFiles.add(file);
                  IOUtils.closeQuietly(directAccess);
                  Report fileReportItem=PluginHelper.initPluginReportItem(this,file.getId(),File.class,AIPState.ACTIVE);
                  fileReportItem.setPluginState(pluginResultState).setPluginDetails(result);
                  reportItem.addReport(fileReportItem);
                }
 catch (                CommandException e) {
                  pluginResultState=PluginState.PARTIAL_SUCCESS;
                  reportState=pluginResultState;
                  reportItem.setPluginState(pluginResultState).addPluginDetails(e.getMessage() + "String_Node_Str" + e.getOutput()+ "String_Node_Str");
                  LOGGER.debug("String_Node_Str",fileFormat,outputFormat,file.getId(),representation.getId(),aip.getId());
                }
              }
 else {
                unchangedFiles.add(file);
                if (ignoreFiles) {
                  validationReport.addIssue(new ValidationIssue(ModelUtils.getFileStoragePath(file).toString()));
                }
 else {
                  pluginResultState=PluginState.FAILURE;
                  reportState=pluginResultState;
                  hasNonPdfFiles=true;
                }
              }
            }
          }
 else {
            LOGGER.error("String_Node_Str",oFile.getCause());
          }
        }
        IOUtils.closeQuietly(allFiles);
        reportItem.setPluginState(pluginResultState);
        if (reportState.equals(PluginState.SUCCESS)) {
          if (ignoreFiles && !validationReport.getIssues().isEmpty()) {
            reportItem.setHtmlPluginDetails(true).setPluginDetails(validationReport.toHtml(false,false,false,"String_Node_Str"));
          }
        }
        if (hasNonPdfFiles) {
          reportItem.setPluginDetails("String_Node_Str");
        }
        if (!alteredFiles.isEmpty() && !createDIP) {
          createNewFilesOnRepresentation(storage,model,unchangedFiles,newRepresentationID,notify);
        }
      }
 catch (      RuntimeException|NotFoundException|GenericException|RequestNotValidException|AuthorizationDeniedException|IOException|AlreadyExistsException e) {
        LOGGER.error("String_Node_Str" + aip.getId() + "String_Node_Str"+ e.getMessage(),e);
        pluginResultState=PluginState.FAILURE;
        reportState=pluginResultState;
        reportItem.setPluginState(pluginResultState).setPluginDetails(e.getMessage());
      }
 finally {
        report.addReport(reportItem);
        PluginHelper.updatePartialJobReport(this,model,reportItem,true,job);
        if (!createDIP) {
          try {
            Representation rep=model.retrieveRepresentation(aip.getId(),newRepresentationID);
            createPremisSkeletonOnRepresentation(model,aip.getId(),rep);
          }
 catch (          RequestNotValidException|GenericException|NotFoundException|AuthorizationDeniedException|ValidationException|IOException|XmlException e) {
            LOGGER.error("String_Node_Str",e.getMessage());
          }
        }
      }
    }
    try {
      LOGGER.debug("String_Node_Str",aip.getId());
      boolean notifyEvent=false;
      createEvent(model,index,aip.getId(),null,null,null,outputFormat,reportState,alteredFiles,newFiles,notifyEvent);
      model.notifyAipUpdated(aip.getId());
      jobPluginInfo.incrementObjectsProcessed(reportState);
    }
 catch (    PluginException|RequestNotValidException|GenericException|NotFoundException|AuthorizationDeniedException e) {
      LOGGER.debug("String_Node_Str");
    }
  }
  return report;
}