Program: 188787
Project: 188787
Buggy source:
private Report executeOnRepresentation(IndexService index,ModelService model,StorageService storage,List<Representation> list,IndexedPreservationAgent agent) throws PluginException {
  List<String> newRepresentations=new ArrayList<String>();
  String aipId=null;
  Report report=PluginHelper.createPluginReport(this);
  String detailExtension="String_Node_Str";
  for (  Representation representation : list) {
    List<File> unchangedFiles=new ArrayList<File>();
    String newRepresentationID=UUID.randomUUID().toString();
    List<File> alteredFiles=new ArrayList<File>();
    List<File> newFiles=new ArrayList<File>();
    aipId=representation.getAipId();
    int pluginResultState=1;
    boolean notify=true;
    ReportItem reportItem=PluginHelper.createPluginReportItem(this,"String_Node_Str",representation.getId(),null);
    try {
      if (!representation.isOriginal()) {
        newRepresentationID=representation.getId();
        newRepresentations.add(representation.getId());
        StoragePath representationPreservationPath=ModelUtils.getRepresentationPreservationMetadataStoragePath(aipId,representation.getId());
        storage.deleteResource(representationPreservationPath);
      }
      LOGGER.debug("String_Node_Str" + representation);
      boolean recursive=true;
      CloseableIterable<File> allFiles=model.listFilesUnder(representation.getAipId(),representation.getId(),recursive);
      for (      File file : allFiles) {
        LOGGER.debug("String_Node_Str" + file);
        if (!file.isDirectory()) {
          IndexedFile ifile=index.retrieve(IndexedFile.class,IdUtils.getFileId(file));
          String fileMimetype=ifile.getFileFormat().getMimeType();
          String filePronom=ifile.getFileFormat().getPronom();
          String fileFormat=ifile.getId().substring(ifile.getId().lastIndexOf('.') + 1);
          List<String> applicableTo=getApplicableTo();
          Map<String,List<String>> pronomToExtension=getPronomToExtension();
          Map<String,List<String>> mimetypeToExtension=getMimetypeToExtension();
          if (((!getInputFormat().isEmpty() && fileFormat.equalsIgnoreCase(getInputFormat())) || (getInputFormat().isEmpty())) && (applicableTo.size() == 0 || (filePronom != null && pronomToExtension.containsKey(filePronom)) || (fileMimetype != null && mimetypeToExtension.containsKey(fileMimetype)) || (applicableTo.contains(fileFormat)))) {
            if (applicableTo.size() > 0) {
              if (filePronom != null && !filePronom.isEmpty() && pronomToExtension.get(filePronom) != null && !pronomToExtension.get(filePronom).contains(fileFormat)) {
                fileFormat=pronomToExtension.get(filePronom).get(0);
              }
 else               if (fileMimetype != null && !fileMimetype.isEmpty() && mimetypeToExtension.get(fileMimetype) != null && !mimetypeToExtension.get(fileMimetype).contains(fileFormat)) {
                fileFormat=mimetypeToExtension.get(fileMimetype).get(0);
              }
            }
            StoragePath fileStoragePath=ModelUtils.getFileStoragePath(file);
            DirectResourceAccess directAccess=storage.getDirectAccess(fileStoragePath);
            LOGGER.debug("String_Node_Str" + fileFormat + "String_Node_Str"+ outputFormat+ "String_Node_Str"+ 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);
              if (!newRepresentations.contains(newRepresentationID)) {
                LOGGER.debug("String_Node_Str" + newRepresentationID + "String_Node_Str"+ aipId);
                boolean original=false;
                newRepresentations.add(newRepresentationID);
                model.createRepresentation(aipId,newRepresentationID,original,notify);
              }
              if (!representation.isOriginal()) {
                model.deleteFile(aipId,newRepresentationID,file.getPath(),file.getId(),notify);
              }
              String newFileId=file.getId().replaceFirst("String_Node_Str","String_Node_Str" + outputFormat);
              File f=model.createFile(aipId,newRepresentationID,file.getPath(),newFileId,payload,notify);
              alteredFiles.add(file);
              newFiles.add(f);
              IOUtils.closeQuietly(directAccess);
              reportItem=PluginHelper.setPluginReportItemInfo(reportItem,representation.getId(),new Attribute(RodaConstants.REPORT_ATTR_OUTCOME,PluginState.SUCCESS.toString()),new Attribute(RodaConstants.REPORT_ATTR_OUTCOME_DETAILS,result));
            }
 catch (            CommandException e) {
              detailExtension+=file.getId() + "String_Node_Str" + e.getOutput();
              pluginResultState=2;
              reportItem=PluginHelper.setPluginReportItemInfo(reportItem,representation.getId(),new Attribute(RodaConstants.REPORT_ATTR_OUTCOME,PluginState.PARTIAL_SUCCESS.toString()),new Attribute(RodaConstants.REPORT_ATTR_OUTCOME_DETAILS,e.getMessage()));
              LOGGER.debug("String_Node_Str" + fileFormat + "String_Node_Str"+ outputFormat+ "String_Node_Str"+ file.getId()+ "String_Node_Str"+ representation.getId()+ "String_Node_Str"+ representation.getAipId());
            }
          }
 else {
            unchangedFiles.add(file);
          }
        }
      }
      IOUtils.closeQuietly(allFiles);
      report.addItem(reportItem);
      if (alteredFiles.size() > 0) {
        if (representation.isOriginal()) {
          for (          File f : unchangedFiles) {
            StoragePath fileStoragePath=ModelUtils.getFileStoragePath(f);
            Binary binary=storage.getBinary(fileStoragePath);
            Path uriPath=Paths.get(binary.getContent().getURI());
            ContentPayload payload=new FSPathContentPayload(uriPath);
            model.createFile(f.getAipId(),newRepresentationID,f.getPath(),f.getId(),payload,notify);
          }
        }
        boolean notifyReindex=false;
        AbstractConvertPluginUtils.reIndexingRepresentation(index,model,storage,aipId,newRepresentationID,notifyReindex);
      }
    }
 catch (    RuntimeException|NotFoundException|GenericException|RequestNotValidException|AuthorizationDeniedException|IOException|AlreadyExistsException|ValidationException|InvalidParameterException|SAXException|TikaException|XmlException e) {
      LOGGER.error("String_Node_Str" + representation.getId() + "String_Node_Str"+ e.getMessage(),e);
      pluginResultState=0;
      reportItem=PluginHelper.setPluginReportItemInfo(reportItem,representation.getId(),new Attribute(RodaConstants.REPORT_ATTR_OUTCOME,PluginState.FAILURE.toString()),new Attribute(RodaConstants.REPORT_ATTR_OUTCOME_DETAILS,e.getMessage()));
      report.addItem(reportItem);
    }
    LOGGER.debug("String_Node_Str" + representation.getId());
    boolean notifyEvent=false;
    createEvent(alteredFiles,newFiles,aipId,newRepresentationID,model,outputFormat,pluginResultState,detailExtension,agent,notifyEvent);
  }
  try {
    model.notifyAIPUpdated(aipId);
  }
 catch (  RODAException e) {
    LOGGER.error("String_Node_Str",e);
  }
  return report;
}

Fixed version (ground truth):
private Report executeOnRepresentation(IndexService index,ModelService model,StorageService storage,List<Representation> list,IndexedPreservationAgent agent) throws PluginException {
  List<String> newRepresentations=new ArrayList<String>();
  String aipId=null;
  Report report=PluginHelper.createPluginReport(this);
  String detailExtension="String_Node_Str";
  for (  Representation representation : list) {
    List<File> unchangedFiles=new ArrayList<File>();
    String newRepresentationID=UUID.randomUUID().toString();
    List<File> alteredFiles=new ArrayList<File>();
    List<File> newFiles=new ArrayList<File>();
    aipId=representation.getAipId();
    int pluginResultState=1;
    boolean notify=true;
    ReportItem reportItem=PluginHelper.createPluginReportItem(this,"String_Node_Str",representation.getId(),null);
    try {
      if (!representation.isOriginal()) {
        newRepresentationID=representation.getId();
        newRepresentations.add(representation.getId());
        StoragePath representationPreservationPath=ModelUtils.getRepresentationPreservationMetadataStoragePath(aipId,representation.getId());
        storage.deleteResource(representationPreservationPath);
      }
      LOGGER.debug("String_Node_Str" + representation);
      boolean recursive=true;
      CloseableIterable<File> allFiles=model.listFilesUnder(representation.getAipId(),representation.getId(),recursive);
      for (      File file : allFiles) {
        LOGGER.debug("String_Node_Str" + file);
        if (!file.isDirectory()) {
          IndexedFile ifile=index.retrieve(IndexedFile.class,IdUtils.getFileId(file));
          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 (((!getInputFormat().isEmpty() && fileFormat.equalsIgnoreCase(getInputFormat())) || (getInputFormat().isEmpty())) && (applicableTo.size() == 0 || (filePronom != null && pronomToExtension.containsKey(filePronom)) || (fileMimetype != null && mimetypeToExtension.containsKey(fileMimetype)) || (applicableTo.contains(fileFormat))) && (convertableTo.size() == 0 || convertableTo.contains(outputFormat))) {
            if (applicableTo.size() > 0) {
              if (filePronom != null && !filePronom.isEmpty() && pronomToExtension.get(filePronom) != null && !pronomToExtension.get(filePronom).contains(fileFormat)) {
                fileFormat=pronomToExtension.get(filePronom).get(0);
              }
 else               if (fileMimetype != null && !fileMimetype.isEmpty() && mimetypeToExtension.get(fileMimetype) != null && !mimetypeToExtension.get(fileMimetype).contains(fileFormat)) {
                fileFormat=mimetypeToExtension.get(fileMimetype).get(0);
              }
            }
            StoragePath fileStoragePath=ModelUtils.getFileStoragePath(file);
            DirectResourceAccess directAccess=storage.getDirectAccess(fileStoragePath);
            LOGGER.debug("String_Node_Str" + fileFormat + "String_Node_Str"+ outputFormat+ "String_Node_Str"+ 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);
              if (!newRepresentations.contains(newRepresentationID)) {
                LOGGER.debug("String_Node_Str" + newRepresentationID + "String_Node_Str"+ aipId);
                boolean original=false;
                newRepresentations.add(newRepresentationID);
                model.createRepresentation(aipId,newRepresentationID,original,notify);
              }
              if (!representation.isOriginal()) {
                model.deleteFile(aipId,newRepresentationID,file.getPath(),file.getId(),notify);
              }
              String newFileId=file.getId().replaceFirst("String_Node_Str","String_Node_Str" + outputFormat);
              File f=model.createFile(aipId,newRepresentationID,file.getPath(),newFileId,payload,notify);
              alteredFiles.add(file);
              newFiles.add(f);
              IOUtils.closeQuietly(directAccess);
              reportItem=PluginHelper.setPluginReportItemInfo(reportItem,representation.getId(),new Attribute(RodaConstants.REPORT_ATTR_OUTCOME,PluginState.SUCCESS.toString()),new Attribute(RodaConstants.REPORT_ATTR_OUTCOME_DETAILS,result));
            }
 catch (            CommandException e) {
              detailExtension+=file.getId() + "String_Node_Str" + e.getOutput();
              pluginResultState=2;
              reportItem=PluginHelper.setPluginReportItemInfo(reportItem,representation.getId(),new Attribute(RodaConstants.REPORT_ATTR_OUTCOME,PluginState.PARTIAL_SUCCESS.toString()),new Attribute(RodaConstants.REPORT_ATTR_OUTCOME_DETAILS,e.getMessage()));
              LOGGER.debug("String_Node_Str" + fileFormat + "String_Node_Str"+ outputFormat+ "String_Node_Str"+ file.getId()+ "String_Node_Str"+ representation.getId()+ "String_Node_Str"+ representation.getAipId());
            }
          }
 else {
            unchangedFiles.add(file);
          }
        }
      }
      IOUtils.closeQuietly(allFiles);
      report.addItem(reportItem);
      if (alteredFiles.size() > 0) {
        if (representation.isOriginal()) {
          for (          File f : unchangedFiles) {
            StoragePath fileStoragePath=ModelUtils.getFileStoragePath(f);
            Binary binary=storage.getBinary(fileStoragePath);
            Path uriPath=Paths.get(binary.getContent().getURI());
            ContentPayload payload=new FSPathContentPayload(uriPath);
            model.createFile(f.getAipId(),newRepresentationID,f.getPath(),f.getId(),payload,notify);
          }
        }
        boolean notifyReindex=false;
        AbstractConvertPluginUtils.reIndexingRepresentation(index,model,storage,aipId,newRepresentationID,notifyReindex);
      }
    }
 catch (    RuntimeException|NotFoundException|GenericException|RequestNotValidException|AuthorizationDeniedException|IOException|AlreadyExistsException|ValidationException|InvalidParameterException|SAXException|TikaException|XmlException e) {
      LOGGER.error("String_Node_Str" + representation.getId() + "String_Node_Str"+ e.getMessage(),e);
      pluginResultState=0;
      reportItem=PluginHelper.setPluginReportItemInfo(reportItem,representation.getId(),new Attribute(RodaConstants.REPORT_ATTR_OUTCOME,PluginState.FAILURE.toString()),new Attribute(RodaConstants.REPORT_ATTR_OUTCOME_DETAILS,e.getMessage()));
      report.addItem(reportItem);
    }
    LOGGER.debug("String_Node_Str" + representation.getId());
    boolean notifyEvent=false;
    createEvent(alteredFiles,newFiles,aipId,newRepresentationID,model,outputFormat,pluginResultState,detailExtension,agent,notifyEvent);
  }
  try {
    model.notifyAIPUpdated(aipId);
  }
 catch (  RODAException e) {
    LOGGER.error("String_Node_Str",e);
  }
  return report;
}