Program: 188773
Project: 188773
Buggy source:
private Report executeOnAIP(IndexService index,ModelService model,StorageService storage,List<AIP> list,IndexedPreservationAgent agent) throws PluginException {
  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 state=1;
      try {
        logger.debug("String_Node_Str" + representation);
        ClosableIterable<File> allFiles=model.listAllFiles(aip.getId(),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,ifile.getId().length());
            if (((!inputFormat.isEmpty() && fileFormat.equalsIgnoreCase(inputFormat)) || inputFormat.isEmpty()) && (applicableTo.size() == 0 || (filePronom != null && pronomToExtension.containsKey(filePronom)) || (fileMimetype != null && mimetypeToExtension.containsKey(fileMimetype)) || applicableTo.contains(fileFormat) || applicableTo.size() == 0) && 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(aip.getId(),representation.getId());
                if (!newRepresentations.contains(newRepresentationID)) {
                  logger.debug("String_Node_Str" + newRepresentationID + "String_Node_Str"+ aip.getId());
                  boolean original=false;
                  newRepresentations.add(newRepresentationID);
                  model.createRepresentation(aip.getId(),newRepresentationID,original,notify);
                  StoragePath storagePreservationPath=ModelUtils.getPreservationPath(aip.getId(),newRepresentationID);
                  model.getStorage().createDirectory(storagePreservationPath);
                }
                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);
              }
 else {
                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());
                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(aip.getId(),representation.getId());
          }
        }
      }
 catch (      Throwable e) {
        logger.error("String_Node_Str" + aip.getId() + "String_Node_Str"+ e.getMessage(),e);
        state=0;
      }
      logger.debug("String_Node_Str" + representation.getId());
      boolean notifyEvent=false;
      createEvent(alteredFiles,newFiles,aip,newRepresentationID,model,state,agent,notifyEvent);
    }
    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 {
  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 state=1;
      try {
        LOGGER.debug("String_Node_Str" + representation);
        ClosableIterable<File> allFiles=model.listAllFiles(aip.getId(),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,ifile.getId().length());
            if (((!inputFormat.isEmpty() && fileFormat.equalsIgnoreCase(inputFormat)) || inputFormat.isEmpty()) && (getApplicableTo().size() == 0 || (filePronom != null && getPronomToExtension().containsKey(filePronom)) || (fileMimetype != null && getMimetypeToExtension().containsKey(fileMimetype)) || getApplicableTo().contains(fileFormat) || getApplicableTo().size() == 0)) {
              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());
              Path pluginResult=Files.createTempFile("String_Node_Str","String_Node_Str" + getOutputFormat());
              String result;
              try {
                result=executePlugin(directAccess.getPath(),pluginResult,fileFormat);
                ContentPayload payload=new FSPathContentPayload(pluginResult);
                StoragePath storagePath=ModelUtils.getRepresentationPath(aip.getId(),representation.getId());
                if (!newRepresentations.contains(newRepresentationID)) {
                  LOGGER.debug("String_Node_Str" + newRepresentationID + "String_Node_Str"+ aip.getId());
                  boolean original=false;
                  newRepresentations.add(newRepresentationID);
                  model.createRepresentation(aip.getId(),newRepresentationID,original,notify);
                  StoragePath storagePreservationPath=ModelUtils.getPreservationPath(aip.getId(),newRepresentationID);
                  model.getStorage().createDirectory(storagePreservationPath);
                }
                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);
              }
 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"+ aip.getId());
                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(aip.getId(),representation.getId());
          }
        }
      }
 catch (      RuntimeException|NotFoundException|GenericException|RequestNotValidException|AuthorizationDeniedException|IOException|AlreadyExistsException e) {
        LOGGER.error("String_Node_Str" + aip.getId() + "String_Node_Str"+ e.getMessage(),e);
        state=0;
      }
      LOGGER.debug("String_Node_Str" + representation.getId());
      boolean notifyEvent=false;
      createEvent(alteredFiles,newFiles,aip,newRepresentationID,model,state,agent,notifyEvent);
    }
    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();
}