Program: 85931
Project: 85931
Buggy source:
@RolesAllowed({UserGroupMapping.REGULAR_USER_ROLE_ID}) @Override public BinaryResource saveFileInPathDataIteration(String workspaceId,String configurationItemId,String serialNumber,int path,int iteration,String fileName,int pSize) throws UserNotFoundException, UserNotActiveException, WorkspaceNotFoundException, NotAllowedException, AccessRightException, ProductInstanceMasterNotFoundException, FileAlreadyExistsException, CreationException {
  User user=userManager.checkWorkspaceReadAccess(workspaceId);
  Locale locale=new Locale(user.getLanguage());
  checkNameFileValidity(fileName,locale);
  ProductInstanceMasterDAO productInstanceMasterDAO=new ProductInstanceMasterDAO(locale,em);
  ProductInstanceMaster prodInstM=productInstanceMasterDAO.loadProductInstanceMaster(new ProductInstanceMasterKey(serialNumber,workspaceId,configurationItemId));
  checkProductInstanceWriteAccess(workspaceId,prodInstM,user);
  ProductInstanceIteration prodInstI=prodInstM.getLastIteration();
  PathDataMasterDAO pathDataMasterDAO=new PathDataMasterDAO(locale,em);
  PathDataMaster pathDataMaster=pathDataMasterDAO.findByPathIdAndProductInstanceIteration(path,prodInstI);
  PathDataIteration pathDataIteration=pathDataMaster.getPathDataIterations().get(iteration - 1);
  if (!prodInstI.getPathDataMasterList().contains(pathDataMaster)) {
    throw new NotAllowedException(locale,"String_Node_Str");
  }
  BinaryResource binaryResource=null;
  String fullName=workspaceId + "String_Node_Str" + prodInstM.getSerialNumber()+ "String_Node_Str"+ pathDataMaster.getId()+ "String_Node_Str"+ iteration+ '/'+ fileName;
  for (  BinaryResource bin : pathDataIteration.getAttachedFiles()) {
    if (bin.getFullName().equals(fullName)) {
      binaryResource=bin;
      break;
    }
  }
  if (binaryResource == null) {
    binaryResource=new BinaryResource(fullName,pSize,new Date());
    new BinaryResourceDAO(locale,em).createBinaryResource(binaryResource);
    pathDataIteration.addFile(binaryResource);
  }
 else {
    binaryResource.setContentLength(pSize);
    binaryResource.setLastModified(new Date());
  }
  return binaryResource;
}

Fixed version (ground truth):
@RolesAllowed({UserGroupMapping.REGULAR_USER_ROLE_ID}) @Override public BinaryResource saveFileInPathDataIteration(String workspaceId,String configurationItemId,String serialNumber,int path,int iteration,String fileName,int pSize) throws UserNotFoundException, UserNotActiveException, WorkspaceNotFoundException, NotAllowedException, AccessRightException, ProductInstanceMasterNotFoundException, FileAlreadyExistsException, CreationException, PathDataMasterNotFoundException {
  User user=userManager.checkWorkspaceReadAccess(workspaceId);
  Locale locale=new Locale(user.getLanguage());
  checkNameFileValidity(fileName,locale);
  ProductInstanceMasterDAO productInstanceMasterDAO=new ProductInstanceMasterDAO(locale,em);
  ProductInstanceMaster prodInstM=productInstanceMasterDAO.loadProductInstanceMaster(new ProductInstanceMasterKey(serialNumber,workspaceId,configurationItemId));
  checkProductInstanceWriteAccess(workspaceId,prodInstM,user);
  ProductInstanceIteration prodInstI=prodInstM.getLastIteration();
  PathDataMasterDAO pathDataMasterDAO=new PathDataMasterDAO(locale,em);
  PathDataMaster pathDataMaster=pathDataMasterDAO.findByPathIdAndProductInstanceIteration(path,prodInstI);
  PathDataIteration pathDataIteration=pathDataMaster.getPathDataIterations().get(iteration - 1);
  if (!prodInstI.getPathDataMasterList().contains(pathDataMaster)) {
    throw new NotAllowedException(locale,"String_Node_Str");
  }
  BinaryResource binaryResource=null;
  String fullName=workspaceId + "String_Node_Str" + prodInstM.getSerialNumber()+ "String_Node_Str"+ pathDataMaster.getId()+ "String_Node_Str"+ iteration+ '/'+ fileName;
  for (  BinaryResource bin : pathDataIteration.getAttachedFiles()) {
    if (bin.getFullName().equals(fullName)) {
      binaryResource=bin;
      break;
    }
  }
  if (binaryResource == null) {
    binaryResource=new BinaryResource(fullName,pSize,new Date());
    new BinaryResourceDAO(locale,em).createBinaryResource(binaryResource);
    pathDataIteration.addFile(binaryResource);
  }
 else {
    binaryResource.setContentLength(pSize);
    binaryResource.setLastModified(new Date());
  }
  return binaryResource;
}