Program: 188788
Project: 188788
Buggy source:
private Report executeOnAIP(IndexService index,ModelService model,StorageService storage,List<AIP> list,IndexedPreservationAgent agent) throws PluginException {
  Report report=PluginHelper.createPluginReport(this);
  String detailExtension="String_Node_Str";
  for (  AIP aip : list) {
    LOGGER.debug("String_Node_Str" + aip.getId());
    List<String> newRepresentations=new ArrayList<String>();
    String newRepresentationID=null;
    boolean notify=true;
    for (    Representation representation : aip.getRepresentations()) {
      List<File> alteredFiles=new ArrayList<File>();
      List<File> newFiles=new ArrayList<File>();
      List<File> unchangedFiles=new ArrayList<File>();
      newRepresentationID=UUID.randomUUID().toString();
      int pluginResultState=1;
      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(aip.getId(),representation.getId());
          storage.deleteResource(representationPreservationPath);
        }
        LOGGER.debug("String_Node_Str" + representation);
        boolean recursive=true;
        CloseableIterable<File> allFiles=model.listFilesUnder(aip.getId(),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,ifile.getId().length());
            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) && representation.isOriginal()) {
                  LOGGER.debug("String_Node_Str" + newRepresentationID + "String_Node_Str"+ aip.getId());
                  boolean original=false;
                  newRepresentations.add(newRepresentationID);
                  model.createRepresentation(aip.getId(),newRepresentationID,original,notify);
                }
                if (!representation.isOriginal()) {
                  model.deleteFile(aip.getId(),newRepresentationID,file.getPath(),file.getId(),notify);
                }
                String newFileId=file.getId().replaceFirst("String_Node_Str","String_Node_Str" + outputFormat);
                File f=model.createFile(aip.getId(),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"+ aip.getId());
              }
            }
 else {
              unchangedFiles.add(file);
            }
          }
        }
        IOUtils.closeQuietly(allFiles);
        if (alteredFiles.size() > 0 && 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);
          }
        }
      }
 catch (      RuntimeException|NotFoundException|GenericException|RequestNotValidException|AuthorizationDeniedException|IOException|AlreadyExistsException e) {
        LOGGER.error("String_Node_Str" + aip.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()));
      }
      LOGGER.debug("String_Node_Str" + representation.getId());
      boolean notifyEvent=false;
      createEvent(alteredFiles,newFiles,aip.getId(),newRepresentationID,model,outputFormat,pluginResultState,detailExtension,agent,notifyEvent);
      report.addItem(reportItem);
    }
    try {
      for (      String repId : newRepresentations) {
        boolean inotify=false;
        AbstractConvertPluginUtils.reIndexingRepresentation(index,model,storage,aip.getId(),repId,inotify);
      }
      model.notifyAIPUpdated(aip.getId());
    }
 catch (    Exception e) {
      LOGGER.debug("String_Node_Str" + newRepresentationID);
    }
  }
  return new Report();
}

Fixed version (ground truth):
private Report executeOnAIP(IndexService index,ModelService model,StorageService storage,List<AIP> list,IndexedPreservationAgent agent) throws PluginException {
  Report report=PluginHelper.createPluginReport(this);
  String detailExtension="String_Node_Str";
  for (  AIP aip : list) {
    LOGGER.debug("String_Node_Str" + aip.getId());
    List<String> newRepresentations=new ArrayList<String>();
    String newRepresentationID=null;
    boolean notify=true;
    for (    Representation representation : aip.getRepresentations()) {
      List<File> alteredFiles=new ArrayList<File>();
      List<File> newFiles=new ArrayList<File>();
      List<File> unchangedFiles=new ArrayList<File>();
      newRepresentationID=UUID.randomUUID().toString();
      int pluginResultState=1;
      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(aip.getId(),representation.getId());
          storage.deleteResource(representationPreservationPath);
        }
        LOGGER.debug("String_Node_Str" + representation);
        boolean recursive=true;
        CloseableIterable<File> allFiles=model.listFilesUnder(aip.getId(),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,ifile.getId().length());
            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) && representation.isOriginal()) {
                  LOGGER.debug("String_Node_Str" + newRepresentationID + "String_Node_Str"+ aip.getId());
                  boolean original=false;
                  newRepresentations.add(newRepresentationID);
                  model.createRepresentation(aip.getId(),newRepresentationID,original,notify);
                }
                if (!representation.isOriginal()) {
                  model.deleteFile(aip.getId(),newRepresentationID,file.getPath(),file.getId(),notify);
                }
                String newFileId=file.getId().replaceFirst("String_Node_Str","String_Node_Str" + outputFormat);
                File f=model.createFile(aip.getId(),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"+ aip.getId());
              }
            }
 else {
              unchangedFiles.add(file);
            }
          }
        }
        IOUtils.closeQuietly(allFiles);
        if (alteredFiles.size() > 0 && 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);
          }
        }
      }
 catch (      RuntimeException|NotFoundException|GenericException|RequestNotValidException|AuthorizationDeniedException|IOException|AlreadyExistsException e) {
        LOGGER.error("String_Node_Str" + aip.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()));
      }
      LOGGER.debug("String_Node_Str" + representation.getId());
      boolean notifyEvent=false;
      createEvent(alteredFiles,newFiles,aip.getId(),newRepresentationID,model,outputFormat,pluginResultState,detailExtension,agent,notifyEvent);
      report.addItem(reportItem);
    }
    try {
      for (      String repId : newRepresentations) {
        boolean inotify=false;
        AbstractConvertPluginUtils.reIndexingRepresentation(index,model,storage,aip.getId(),repId,inotify);
      }
      model.notifyAIPUpdated(aip.getId());
    }
 catch (    Exception e) {
      LOGGER.debug("String_Node_Str" + newRepresentationID);
    }
  }
  return new Report();
}