Program: 188312
Project: 188312
Buggy source:
@Override protected Report executeOnFile(IndexService index,ModelService model,StorageService storage,Report report,SimpleJobPluginInfo jobPluginInfo,List<File> list,Job job) throws PluginException {
  Map<String,String> changedRepresentationsOnAIPs=new HashMap<>();
  boolean notify=true;
  String newRepresentationID=null;
  String newFileId=null;
  ArrayList<File> newFiles=new ArrayList<>();
  ArrayList<DIPFile> newDIPFiles=new ArrayList<>();
  Report reportItem=null;
  PluginState reportState=PluginState.SUCCESS;
  PluginState pluginResultState=PluginState.SUCCESS;
  for (  File file : list) {
    try {
      LOGGER.debug("String_Node_Str",file.getId());
      newRepresentationID=IdUtils.createUUID();
      pluginResultState=PluginState.SUCCESS;
      reportItem=PluginHelper.initPluginReportItem(this,IdUtils.getFileId(file),File.class,AIPState.ACTIVE);
      if (createDIP) {
        reportItem.setOutcomeObjectClass(DIP.class.getName());
      }
      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);
        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);
            ContentPayload payload=new FSPathContentPayload(pluginResult);
            StoragePath storagePath=ModelUtils.getRepresentationStoragePath(file.getAipId(),file.getRepresentationId());
            LOGGER.debug("String_Node_Str",newRepresentationID,file.getAipId());
            boolean original=false;
            if (createDIP) {
              FileLink fileLink=new FileLink(file.getAipId(),file.getRepresentationId(),file.getPath(),file.getId());
              List<FileLink> links=new ArrayList<>();
              links.add(fileLink);
              AIP aip=model.retrieveAIP(file.getAipId());
              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();
            }
 else {
              String newRepresentationType=RodaConstants.REPRESENTATION_TYPE_MIXED;
              model.createRepresentation(file.getAipId(),newRepresentationID,original,newRepresentationType,model.getStorage(),storagePath);
            }
            newFileId=file.getId().replaceFirst("String_Node_Str","String_Node_Str" + outputFormat);
            if (createDIP) {
              DIPFile f=model.createDIPFile(newRepresentationID,file.getPath(),newFileId,directAccess.getPath().toFile().length(),payload,notify);
              newDIPFiles.add(f);
            }
 else {
              model.deleteFile(file.getAipId(),newRepresentationID,file.getPath(),file.getId(),notify);
              File f=model.createFile(file.getAipId(),newRepresentationID,file.getPath(),newFileId,payload,notify);
              newFiles.add(f);
              reportItem.setOutcomeObjectId(IdUtils.getFileId(f));
              changedRepresentationsOnAIPs.put(file.getRepresentationId(),file.getAipId());
            }
            Report fileReportItem=PluginHelper.initPluginReportItem(this,file.getId(),File.class,AIPState.ACTIVE);
            fileReportItem.setPluginState(PluginState.SUCCESS).setPluginDetails(result);
            reportItem.addReport(fileReportItem);
          }
 catch (          CommandException e) {
            pluginResultState=PluginState.PARTIAL_SUCCESS;
            Report fileReportItem=PluginHelper.initPluginReportItem(this,file.getId(),File.class,AIPState.ACTIVE);
            fileReportItem.setPluginState(PluginState.PARTIAL_SUCCESS).setPluginDetails(e.getMessage() + "String_Node_Str" + e.getOutput());
            reportItem.addReport(fileReportItem);
            LOGGER.debug("String_Node_Str",fileFormat,outputFormat,file.getId(),file.getRepresentationId(),file.getAipId());
          }
        }
 else {
          if (ignoreFiles) {
            reportItem.setPluginDetails("String_Node_Str");
          }
 else {
            pluginResultState=PluginState.FAILURE;
            reportItem.setPluginDetails("String_Node_Str");
          }
        }
      }
      if (!pluginResultState.equals(PluginState.SUCCESS)) {
        reportState=PluginState.FAILURE;
        jobPluginInfo.incrementObjectsProcessedWithFailure();
      }
 else {
        jobPluginInfo.incrementObjectsProcessedWithSuccess();
      }
    }
 catch (    RuntimeException|NotFoundException|GenericException|RequestNotValidException|AuthorizationDeniedException|ValidationException|IOException|AlreadyExistsException e) {
      LOGGER.error("String_Node_Str",file.getId(),e.getMessage(),e);
      reportState=PluginState.FAILURE;
      reportItem.setPluginDetails(e.getMessage());
      jobPluginInfo.incrementObjectsProcessedWithFailure();
    }
 finally {
      reportItem.setPluginState(pluginResultState);
      report.addReport(reportItem);
      PluginHelper.updatePartialJobReport(this,model,reportItem,true,job);
    }
    boolean notifyEvent=false;
    createEvent(model,index,file.getAipId(),file.getRepresentationId(),file.getPath(),file.getId(),outputFormat,reportState,Arrays.asList(file),newFiles,notifyEvent);
    if (!createDIP) {
      try {
        Representation rep=model.retrieveRepresentation(file.getAipId(),newRepresentationID);
        createPremisSkeletonOnRepresentation(model,file.getAipId(),rep);
      }
 catch (      RequestNotValidException|GenericException|NotFoundException|AuthorizationDeniedException|ValidationException|IOException|XmlException e) {
        LOGGER.error("String_Node_Str",e.getMessage());
      }
    }
  }
  return report;
}

Fixed version (ground truth):
@Override protected Report executeOnFile(IndexService index,ModelService model,StorageService storage,Report report,SimpleJobPluginInfo jobPluginInfo,List<File> list,Job job) throws PluginException {
  Map<String,String> changedRepresentationsOnAIPs=new HashMap<>();
  boolean notify=true;
  String newRepresentationID=null;
  String newFileId=null;
  ArrayList<File> newFiles=new ArrayList<>();
  ArrayList<DIPFile> newDIPFiles=new ArrayList<>();
  Report reportItem=null;
  PluginState reportState=PluginState.SUCCESS;
  PluginState pluginResultState=PluginState.SUCCESS;
  for (  File file : list) {
    try {
      LOGGER.debug("String_Node_Str",file.getId());
      newRepresentationID=IdUtils.createUUID();
      pluginResultState=PluginState.SUCCESS;
      reportItem=PluginHelper.initPluginReportItem(this,IdUtils.getFileId(file),File.class,AIPState.ACTIVE);
      if (createDIP) {
        reportItem.setOutcomeObjectClass(DIP.class.getName());
      }
      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);
        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);
            ContentPayload payload=new FSPathContentPayload(pluginResult);
            StoragePath storagePath=ModelUtils.getRepresentationStoragePath(file.getAipId(),file.getRepresentationId());
            LOGGER.debug("String_Node_Str",newRepresentationID,file.getAipId());
            boolean original=false;
            if (createDIP) {
              FileLink fileLink=new FileLink(file.getAipId(),file.getRepresentationId(),file.getPath(),file.getId());
              List<FileLink> links=new ArrayList<>();
              links.add(fileLink);
              AIP aip=model.retrieveAIP(file.getAipId());
              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();
            }
 else {
              String newRepresentationType=RodaConstants.REPRESENTATION_TYPE_MIXED;
              Representation newRep=model.createRepresentation(file.getAipId(),newRepresentationID,original,newRepresentationType,model.getStorage(),storagePath);
              StoragePath metadataPath=ModelUtils.getRepresentationMetadataStoragePath(newRep.getAipId(),newRep.getId());
              storage.deleteResource(metadataPath);
              storage.createDirectory(metadataPath);
            }
            newFileId=file.getId().replaceFirst("String_Node_Str","String_Node_Str" + outputFormat);
            if (createDIP) {
              DIPFile f=model.createDIPFile(newRepresentationID,file.getPath(),newFileId,directAccess.getPath().toFile().length(),payload,notify);
              newDIPFiles.add(f);
            }
 else {
              model.deleteFile(file.getAipId(),newRepresentationID,file.getPath(),file.getId(),notify);
              File f=model.createFile(file.getAipId(),newRepresentationID,file.getPath(),newFileId,payload,notify);
              newFiles.add(f);
              reportItem.setOutcomeObjectId(IdUtils.getFileId(f));
              changedRepresentationsOnAIPs.put(file.getRepresentationId(),file.getAipId());
            }
            Report fileReportItem=PluginHelper.initPluginReportItem(this,file.getId(),File.class,AIPState.ACTIVE);
            fileReportItem.setPluginState(PluginState.SUCCESS).setPluginDetails(result);
            reportItem.addReport(fileReportItem);
          }
 catch (          CommandException e) {
            pluginResultState=PluginState.PARTIAL_SUCCESS;
            Report fileReportItem=PluginHelper.initPluginReportItem(this,file.getId(),File.class,AIPState.ACTIVE);
            fileReportItem.setPluginState(PluginState.PARTIAL_SUCCESS).setPluginDetails(e.getMessage() + "String_Node_Str" + e.getOutput());
            reportItem.addReport(fileReportItem);
            LOGGER.debug("String_Node_Str",fileFormat,outputFormat,file.getId(),file.getRepresentationId(),file.getAipId());
          }
        }
 else {
          if (ignoreFiles) {
            reportItem.setPluginDetails("String_Node_Str");
          }
 else {
            pluginResultState=PluginState.FAILURE;
            reportItem.setPluginDetails("String_Node_Str");
          }
        }
      }
      if (!pluginResultState.equals(PluginState.SUCCESS)) {
        reportState=PluginState.FAILURE;
        jobPluginInfo.incrementObjectsProcessedWithFailure();
      }
 else {
        jobPluginInfo.incrementObjectsProcessedWithSuccess();
      }
    }
 catch (    RuntimeException|NotFoundException|GenericException|RequestNotValidException|AuthorizationDeniedException|ValidationException|IOException|AlreadyExistsException e) {
      LOGGER.error("String_Node_Str",file.getId(),e.getMessage(),e);
      reportState=PluginState.FAILURE;
      reportItem.setPluginDetails(e.getMessage());
      jobPluginInfo.incrementObjectsProcessedWithFailure();
    }
 finally {
      reportItem.setPluginState(pluginResultState);
      report.addReport(reportItem);
      PluginHelper.updatePartialJobReport(this,model,reportItem,true,job);
    }
    boolean notifyEvent=false;
    createEvent(model,index,file.getAipId(),file.getRepresentationId(),file.getPath(),file.getId(),outputFormat,reportState,Arrays.asList(file),newFiles,notifyEvent);
    if (!createDIP) {
      try {
        Representation rep=model.retrieveRepresentation(file.getAipId(),newRepresentationID);
        createPremisSkeletonOnRepresentation(model,file.getAipId(),rep);
      }
 catch (      RequestNotValidException|GenericException|NotFoundException|AuthorizationDeniedException|ValidationException|IOException|XmlException e) {
        LOGGER.error("String_Node_Str",e.getMessage());
      }
    }
  }
  return report;
}