Program: 85978
Project: 85978
Buggy source:
@RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override public DocumentMasterTemplate createDocumentMasterTemplate(String pWorkspaceId,String pId,String pDocumentType,String pWorkflowModelId,String pMask,InstanceAttributeTemplate[] pAttributeTemplates,String[] lovNames,boolean idGenerated,boolean attributesLocked) throws WorkspaceNotFoundException, AccessRightException, DocumentMasterTemplateAlreadyExistsException, UserNotFoundException, NotAllowedException, CreationException, WorkflowModelNotFoundException, ListOfValuesNotFoundException {
  User user=userManager.checkWorkspaceWriteAccess(pWorkspaceId);
  Locale locale=new Locale(user.getLanguage());
  checkNameValidity(pId,locale);
  if (!NamingConvention.correctNameMask(pMask)) {
    throw new NotAllowedException(locale,"String_Node_Str");
  }
  DocumentMasterTemplate template=new DocumentMasterTemplate(user.getWorkspace(),pId,user,pDocumentType,pMask);
  Date now=new Date();
  template.setCreationDate(now);
  template.setIdGenerated(idGenerated);
  template.setAttributesLocked(attributesLocked);
  LOVDAO lovDAO=new LOVDAO(locale,em);
  List<InstanceAttributeTemplate> attrs=new ArrayList<>();
  for (int i=0; i < pAttributeTemplates.length; i++) {
    attrs.add(pAttributeTemplates[i]);
    if (pAttributeTemplates[i] instanceof ListOfValuesAttributeTemplate) {
      ListOfValuesAttributeTemplate lovAttr=(ListOfValuesAttributeTemplate)pAttributeTemplates[i];
      ListOfValuesKey lovKey=new ListOfValuesKey(user.getWorkspaceId(),lovNames[i]);
      lovAttr.setLov(lovDAO.loadLOV(lovKey));
    }
  }
  template.setAttributeTemplates(attrs);
  if (pWorkflowModelId != null) {
    WorkflowModel workflowModel=new WorkflowModelDAO(locale,em).loadWorkflowModel(new WorkflowModelKey(user.getWorkspaceId(),pWorkflowModelId));
    template.setWorkflowModel(workflowModel);
  }
  new DocumentMasterTemplateDAO(locale,em).createDocMTemplate(template);
  return template;
}

Fixed version (ground truth):
@RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override public DocumentMasterTemplate createDocumentMasterTemplate(String pWorkspaceId,String pId,String pDocumentType,String pWorkflowModelId,String pMask,InstanceAttributeTemplate[] pAttributeTemplates,String[] lovNames,boolean idGenerated,boolean attributesLocked) throws WorkspaceNotFoundException, AccessRightException, DocumentMasterTemplateAlreadyExistsException, UserNotFoundException, NotAllowedException, CreationException, WorkflowModelNotFoundException, ListOfValuesNotFoundException {
  User user=userManager.checkWorkspaceWriteAccess(pWorkspaceId);
  Locale locale=new Locale(user.getLanguage());
  checkNameValidity(pId,locale);
  if (pMask != null && !pMask.isEmpty() && !NamingConvention.correctNameMask(pMask)) {
    throw new NotAllowedException(locale,"String_Node_Str");
  }
  DocumentMasterTemplate template=new DocumentMasterTemplate(user.getWorkspace(),pId,user,pDocumentType,pMask);
  Date now=new Date();
  template.setCreationDate(now);
  template.setIdGenerated(idGenerated);
  template.setAttributesLocked(attributesLocked);
  LOVDAO lovDAO=new LOVDAO(locale,em);
  List<InstanceAttributeTemplate> attrs=new ArrayList<>();
  for (int i=0; i < pAttributeTemplates.length; i++) {
    attrs.add(pAttributeTemplates[i]);
    if (pAttributeTemplates[i] instanceof ListOfValuesAttributeTemplate) {
      ListOfValuesAttributeTemplate lovAttr=(ListOfValuesAttributeTemplate)pAttributeTemplates[i];
      ListOfValuesKey lovKey=new ListOfValuesKey(user.getWorkspaceId(),lovNames[i]);
      lovAttr.setLov(lovDAO.loadLOV(lovKey));
    }
  }
  template.setAttributeTemplates(attrs);
  if (pWorkflowModelId != null) {
    WorkflowModel workflowModel=new WorkflowModelDAO(locale,em).loadWorkflowModel(new WorkflowModelKey(user.getWorkspaceId(),pWorkflowModelId));
    template.setWorkflowModel(workflowModel);
  }
  new DocumentMasterTemplateDAO(locale,em).createDocMTemplate(template);
  return template;
}