Program: 85929
Project: 85929
Buggy source:
@RolesAllowed({UserGroupMapping.REGULAR_USER_ROLE_ID}) @Override public PathDataMaster addNewPathDataIteration(String workspaceId,String configurationItemId,String serialNumber,int pathDataId,String path,List<InstanceAttribute> attributes,String note,DocumentRevisionKey[] links,String[] documentLinkComments) throws UserNotFoundException, AccessRightException, WorkspaceNotFoundException, ProductInstanceMasterNotFoundException, UserNotActiveException, NotAllowedException, PathDataAlreadyExistsException, FileAlreadyExistsException, CreationException {
  User user=userManager.checkWorkspaceReadAccess(workspaceId);
  Locale locale=new Locale(user.getLanguage());
  ProductInstanceMasterDAO productInstanceMasterDAO=new ProductInstanceMasterDAO(locale,em);
  ProductInstanceMaster prodInstM=productInstanceMasterDAO.loadProductInstanceMaster(new ProductInstanceMasterKey(serialNumber,workspaceId,configurationItemId));
  checkProductInstanceWriteAccess(workspaceId,prodInstM,user);
  PathDataMasterDAO pathDataMasterDAO=new PathDataMasterDAO(locale,em);
  ProductInstanceIteration prodInstI=prodInstM.getLastIteration();
  for (  PathDataMaster pathDataMaster : prodInstI.getPathDataMasterList()) {
    if (pathDataMaster.getPath() != null && pathDataMaster.getPath().equals(path)) {
      pathDataMaster=pathDataMasterDAO.findByPathIdAndProductInstanceIteration(pathDataId,prodInstI);
      BinaryResourceDAO binDAO=new BinaryResourceDAO(locale,em);
      Set<BinaryResource> sourceFiles=pathDataMaster.getLastIteration().getAttachedFiles();
      Set<BinaryResource> targetFiles=new HashSet<>();
      if (pathDataMaster.getLastIteration() != null) {
        int iteration=pathDataMaster.getLastIteration().getIteration() + 1;
        if (!sourceFiles.isEmpty()) {
          for (          BinaryResource sourceFile : sourceFiles) {
            String fileName=sourceFile.getName();
            long length=sourceFile.getContentLength();
            Date lastModified=sourceFile.getLastModified();
            String fullName=workspaceId + "String_Node_Str" + serialNumber+ "String_Node_Str"+ pathDataId+ "String_Node_Str"+ iteration+ '/'+ fileName;
            BinaryResource targetFile=new BinaryResource(fullName,length,lastModified);
            binDAO.createBinaryResource(targetFile);
            targetFiles.add(targetFile);
            try {
              dataManager.copyData(sourceFile,targetFile);
            }
 catch (            StorageException e) {
              LOGGER.log(Level.INFO,null,e);
            }
          }
        }
      }
      PathDataIteration pathDataIteration=pathDataMaster.createNextIteration();
      pathDataIteration.setInstanceAttributes(attributes);
      pathDataIteration.setIterationNote(note);
      pathDataIteration=createDocumentLink(locale,pathDataIteration,links,documentLinkComments);
      pathDataIteration.setAttachedFiles(targetFiles);
      PathDataIterationDAO pathDataIterationDAO=new PathDataIterationDAO(em);
      pathDataIterationDAO.createPathDataIteration(pathDataIteration);
      return pathDataMaster;
    }
  }
  PathDataMaster pathDataMaster=new PathDataMaster();
  pathDataMaster.setPath(path);
  PathDataIteration pathDataIteration=pathDataMaster.createNextIteration();
  pathDataIteration.setInstanceAttributes(attributes);
  pathDataIteration.setIterationNote(note);
  pathDataMasterDAO.createPathData(pathDataMaster);
  PathDataIterationDAO pathDataIterationDAO=new PathDataIterationDAO(em);
  pathDataIteration=this.createDocumentLink(locale,pathDataIteration,links,documentLinkComments);
  pathDataIterationDAO.createPathDataIteration(pathDataIteration);
  prodInstI.getPathDataMasterList().add(pathDataMaster);
  return pathDataMaster;
}

Fixed version (ground truth):
@RolesAllowed({UserGroupMapping.REGULAR_USER_ROLE_ID}) @Override public PathDataMaster addNewPathDataIteration(String workspaceId,String configurationItemId,String serialNumber,int pathDataId,List<InstanceAttribute> attributes,String note,DocumentRevisionKey[] links,String[] documentLinkComments) throws UserNotFoundException, AccessRightException, WorkspaceNotFoundException, ProductInstanceMasterNotFoundException, UserNotActiveException, NotAllowedException, PathDataAlreadyExistsException, FileAlreadyExistsException, CreationException, PathDataMasterNotFoundException {
  User user=userManager.checkWorkspaceReadAccess(workspaceId);
  Locale locale=new Locale(user.getLanguage());
  ProductInstanceMasterDAO productInstanceMasterDAO=new ProductInstanceMasterDAO(locale,em);
  ProductInstanceMaster prodInstM=productInstanceMasterDAO.loadProductInstanceMaster(new ProductInstanceMasterKey(serialNumber,workspaceId,configurationItemId));
  checkProductInstanceWriteAccess(workspaceId,prodInstM,user);
  PathDataMasterDAO pathDataMasterDAO=new PathDataMasterDAO(locale,em);
  ProductInstanceIteration prodInstI=prodInstM.getLastIteration();
  PathDataMaster pathDataMaster=pathDataMasterDAO.findByPathIdAndProductInstanceIteration(pathDataId,prodInstI);
  BinaryResourceDAO binDAO=new BinaryResourceDAO(locale,em);
  Set<BinaryResource> sourceFiles=pathDataMaster.getLastIteration().getAttachedFiles();
  Set<BinaryResource> targetFiles=new HashSet<>();
  if (pathDataMaster.getLastIteration() != null) {
    int iteration=pathDataMaster.getLastIteration().getIteration() + 1;
    if (!sourceFiles.isEmpty()) {
      for (      BinaryResource sourceFile : sourceFiles) {
        String fileName=sourceFile.getName();
        long length=sourceFile.getContentLength();
        Date lastModified=sourceFile.getLastModified();
        String fullName=workspaceId + "String_Node_Str" + serialNumber+ "String_Node_Str"+ pathDataId+ "String_Node_Str"+ iteration+ '/'+ fileName;
        BinaryResource targetFile=new BinaryResource(fullName,length,lastModified);
        binDAO.createBinaryResource(targetFile);
        targetFiles.add(targetFile);
        try {
          dataManager.copyData(sourceFile,targetFile);
        }
 catch (        StorageException e) {
          LOGGER.log(Level.INFO,null,e);
        }
      }
    }
  }
  PathDataIteration pathDataIteration=pathDataMaster.createNextIteration();
  pathDataIteration.setInstanceAttributes(attributes);
  pathDataIteration.setIterationNote(note);
  createDocumentLink(locale,pathDataIteration,links,documentLinkComments);
  pathDataIteration.setAttachedFiles(targetFiles);
  PathDataIterationDAO pathDataIterationDAO=new PathDataIterationDAO(em);
  pathDataIterationDAO.createPathDataIteration(pathDataIteration);
  return pathDataMaster;
}