Program: 85993
Project: 85993
Buggy source:
@RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override public DocumentRevision[] createDocumentRevision(DocumentRevisionKey pOriginalDocRPK,String pTitle,String pDescription,String pWorkflowModelId,ACLUserEntry[] pACLUserEntries,ACLUserGroupEntry[] pACLUserGroupEntries,Map<String,String> roleMappings) throws UserNotFoundException, AccessRightException, WorkspaceNotFoundException, NotAllowedException, DocumentRevisionAlreadyExistsException, CreationException, WorkflowModelNotFoundException, RoleNotFoundException, DocumentRevisionNotFoundException, FileAlreadyExistsException {
}

Fixed version (ground truth):
@RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override public DocumentRevision[] createDocumentRevision(DocumentRevisionKey pOriginalDocRPK,String pTitle,String pDescription,String pWorkflowModelId,ACLUserEntry[] pACLUserEntries,ACLUserGroupEntry[] pACLUserGroupEntries,Map<String,String> roleMappings) throws UserNotFoundException, AccessRightException, WorkspaceNotFoundException, NotAllowedException, DocumentRevisionAlreadyExistsException, CreationException, WorkflowModelNotFoundException, RoleNotFoundException, DocumentRevisionNotFoundException, FileAlreadyExistsException {
  User user=userManager.checkWorkspaceWriteAccess(pOriginalDocRPK.getDocumentMaster().getWorkspace());
  Locale userLocale=new Locale(user.getLanguage());
  DocumentRevisionDAO docRDAO=new DocumentRevisionDAO(userLocale,em);
  DocumentRevision originalDocR=docRDAO.loadDocR(pOriginalDocRPK);
  DocumentMaster docM=originalDocR.getDocumentMaster();
  Folder folder=originalDocR.getLocation();
  checkFolderWritingRight(user,folder);
  if (originalDocR.isCheckedOut()) {
    throw new NotAllowedException(userLocale,"String_Node_Str");
  }
  if (originalDocR.getNumberOfIterations() == 0) {
    throw new NotAllowedException(userLocale,"String_Node_Str");
  }
  DocumentRevision docR=docM.createNextRevision(user);
  DocumentIteration lastDoc=originalDocR.getLastIteration();
  DocumentIteration firstIte=docR.createNextIteration(user);
  if (lastDoc != null) {
    BinaryResourceDAO binDAO=new BinaryResourceDAO(userLocale,em);
    for (    BinaryResource sourceFile : lastDoc.getAttachedFiles()) {
      String fileName=sourceFile.getName();
      long length=sourceFile.getContentLength();
      Date lastModified=sourceFile.getLastModified();
      String fullName=docR.getWorkspaceId() + "String_Node_Str" + docR.getId()+ "String_Node_Str"+ docR.getVersion()+ "String_Node_Str"+ fileName;
      BinaryResource targetFile=new BinaryResource(fullName,length,lastModified);
      binDAO.createBinaryResource(targetFile);
      firstIte.addFile(targetFile);
      try {
        dataManager.copyData(sourceFile,targetFile);
      }
 catch (      StorageException e) {
        LOGGER.log(Level.INFO,null,e);
      }
    }
    Set<DocumentLink> links=new HashSet<>();
    for (    DocumentLink link : lastDoc.getLinkedDocuments()) {
      DocumentLink newLink=link.clone();
      links.add(newLink);
    }
    firstIte.setLinkedDocuments(links);
    List<InstanceAttribute> attrs=new ArrayList<>();
    for (    InstanceAttribute attr : lastDoc.getInstanceAttributes()) {
      InstanceAttribute clonedAttribute=attr.clone();
      attrs.add(clonedAttribute);
    }
    firstIte.setInstanceAttributes(attrs);
  }
  if (pWorkflowModelId != null) {
    UserDAO userDAO=new UserDAO(userLocale,em);
    RoleDAO roleDAO=new RoleDAO(userLocale,em);
    Map<Role,User> roleUserMap=new HashMap<>();
    for (    Object o : roleMappings.entrySet()) {
      Map.Entry pairs=(Map.Entry)o;
      String roleName=(String)pairs.getKey();
      String userLogin=(String)pairs.getValue();
      User worker=userDAO.loadUser(new UserKey(pOriginalDocRPK.getDocumentMaster().getWorkspace(),userLogin));
      Role role=roleDAO.loadRole(new RoleKey(pOriginalDocRPK.getDocumentMaster().getWorkspace(),roleName));
      roleUserMap.put(role,worker);
    }
    WorkflowModel workflowModel=new WorkflowModelDAO(userLocale,em).loadWorkflowModel(new WorkflowModelKey(user.getWorkspaceId(),pWorkflowModelId));
    Workflow workflow=workflowModel.createWorkflow(roleUserMap);
    docR.setWorkflow(workflow);
    Collection<Task> runningTasks=workflow.getRunningTasks();
    for (    Task runningTask : runningTasks) {
      runningTask.start();
    }
    mailer.sendApproval(runningTasks,docR);
  }
  docR.setTitle(pTitle);
  docR.setDescription(pDescription);
  Map<String,String> userEntries=new HashMap<>();
  Map<String,String> groupEntries=new HashMap<>();
  for (  ACLUserEntry entry : pACLUserEntries) {
    userEntries.put(entry.getPrincipalLogin(),entry.getPermission().name());
  }
  for (  ACLUserGroupEntry entry : pACLUserGroupEntries) {
    groupEntries.put(entry.getPrincipal().getId(),entry.getPermission().name());
  }
  ACLFactory aclFactory=new ACLFactory(em);
  ACL acl=aclFactory.createACL(docR.getWorkspaceId(),userEntries,groupEntries);
  docR.setACL(acl);
  Date now=new Date();
  docR.setCreationDate(now);
  docR.setLocation(folder);
  docR.setCheckOutUser(user);
  docR.setCheckOutDate(now);
  firstIte.setCreationDate(now);
  docRDAO.createDocR(docR);
  return new DocumentRevision[]{originalDocR,docR};
}