Program: 188771
Project: 188771
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;
  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 state=1;
    boolean notify=true;
    try {
      logger.debug("String_Node_Str" + representation);
      ClosableIterable<File> allFiles=model.listAllFiles(aipId,representation.getId());
      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);
          if (((!inputFormat.isEmpty() && fileFormat.equalsIgnoreCase(inputFormat)) || (inputFormat.isEmpty())) && (applicableTo.size() == 0 || (filePronom != null && pronomToExtension.containsKey(filePronom)) || (fileMimetype != null && mimetypeToExtension.containsKey(fileMimetype)) || (applicableTo.contains(fileFormat))) && ifile.getSize() < (maxKbytes * 1024)) {
            if (applicableTo.size() > 0) {
              if (filePronom != null && !filePronom.isEmpty() && !pronomToExtension.get(filePronom).contains(fileFormat)) {
                fileFormat=pronomToExtension.get(filePronom).get(0);
              }
 else               if (fileMimetype != null && !fileMimetype.isEmpty() && !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());
            Path pluginResult=executePlugin(directAccess.getPath(),fileFormat);
            if (pluginResult != null) {
              ContentPayload payload=new FSPathContentPayload(pluginResult);
              StoragePath storagePath=ModelUtils.getRepresentationPath(aipId,representation.getId());
              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);
                StoragePath storagePreservationPath=ModelUtils.getAIPRepresentationPreservationPath(aipId,newRepresentationID);
                model.getStorage().createDirectory(storagePreservationPath);
              }
              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);
            }
 else {
              logger.debug("String_Node_Str" + fileFormat + "String_Node_Str"+ outputFormat+ "String_Node_Str"+ file.getId()+ "String_Node_Str"+ representation.getId()+ "String_Node_Str"+ aipId);
              state=2;
            }
          }
 else {
            unchangedFiles.add(file);
          }
        }
      }
      IOUtils.closeQuietly(allFiles);
      if (alteredFiles.size() > 0) {
        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);
        }
        if (!representation.isOriginal()) {
          model.deleteRepresentation(aipId,representation.getId());
        }
        boolean notifyReindex=false;
        AbstractConvertPluginUtils.reIndexingRepresentation(index,model,storage,aipId,newRepresentationID,notifyReindex);
        logger.debug("String_Node_Str" + representation.getId());
        boolean notifyEvent=false;
        createEvent(alteredFiles,newFiles,model.retrieveAIP(aipId),newRepresentationID,model,state,agent,notifyEvent);
      }
    }
 catch (    Throwable e) {
      logger.error("String_Node_Str" + representation.getId() + "String_Node_Str"+ e.getMessage(),e);
      state=0;
    }
  }
  try {
    model.notifyAIPUpdated(aipId);
  }
 catch (  RODAException e) {
    logger.error("String_Node_Str",e);
  }
  return new 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;
  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 state=1;
    boolean notify=true;
    try {
      LOGGER.debug("String_Node_Str" + representation);
      ClosableIterable<File> allFiles=model.listAllFiles(aipId,representation.getId());
      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);
          if (((!inputFormat.isEmpty() && fileFormat.equalsIgnoreCase(inputFormat)) || (inputFormat.isEmpty())) && (getApplicableTo().size() == 0 || (filePronom != null && getPronomToExtension().containsKey(filePronom)) || (fileMimetype != null && getMimetypeToExtension().containsKey(fileMimetype)) || (getApplicableTo().contains(fileFormat)))) {
            if (getApplicableTo().size() > 0) {
              if (filePronom != null && !filePronom.isEmpty() && !getPronomToExtension().get(filePronom).contains(fileFormat)) {
                fileFormat=getPronomToExtension().get(filePronom).get(0);
              }
 else               if (fileMimetype != null && !fileMimetype.isEmpty() && !getMimetypeToExtension().get(fileMimetype).contains(fileFormat)) {
                fileFormat=getMimetypeToExtension().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);
              StoragePath storagePath=ModelUtils.getRepresentationPath(aipId,representation.getId());
              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);
                StoragePath storagePreservationPath=ModelUtils.getAIPRepresentationPreservationPath(aipId,newRepresentationID);
                model.getStorage().createDirectory(storagePreservationPath);
              }
              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);
            }
 catch (            CommandException e) {
              e.getOutput();
              e.getExitCode();
              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());
              state=2;
            }
          }
 else {
            unchangedFiles.add(file);
          }
        }
      }
      IOUtils.closeQuietly(allFiles);
      if (alteredFiles.size() > 0) {
        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);
        }
        if (!representation.isOriginal()) {
          model.deleteRepresentation(aipId,representation.getId());
        }
        boolean notifyReindex=false;
        AbstractConvertPluginUtils.reIndexingRepresentation(index,model,storage,aipId,newRepresentationID,notifyReindex);
        LOGGER.debug("String_Node_Str" + representation.getId());
        boolean notifyEvent=false;
        createEvent(alteredFiles,newFiles,model.retrieveAIP(aipId),newRepresentationID,model,state,agent,notifyEvent);
      }
    }
 catch (    Throwable e) {
      LOGGER.error("String_Node_Str" + representation.getId() + "String_Node_Str"+ e.getMessage(),e);
      state=0;
    }
  }
  try {
    model.notifyAIPUpdated(aipId);
  }
 catch (  RODAException e) {
    LOGGER.error("String_Node_Str",e);
  }
  return new Report();
}