Program: 85946
Project: 85946
Buggy source:
@RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override public PartRevision updatePartIteration(PartIterationKey pKey,String pIterationNote,Source source,List<PartUsageLink> pUsageLinks,List<InstanceAttribute> pAttributes,List<InstanceAttributeTemplate> pAttributeTemplates,DocumentRevisionKey[] pLinkKeys,String[] documentLinkComments,String[] lovNames) throws UserNotFoundException, WorkspaceNotFoundException, AccessRightException, NotAllowedException, PartRevisionNotFoundException, PartMasterNotFoundException, EntityConstraintException, UserNotActiveException, ListOfValuesNotFoundException, PartUsageLinkNotFoundException {
  User user=userManager.checkWorkspaceWriteAccess(pKey.getWorkspaceId());
  Locale locale=new Locale(user.getLanguage());
  PartRevisionDAO partRDAO=new PartRevisionDAO(locale,em);
  PartRevision partRev=partRDAO.loadPartR(pKey.getPartRevision());
  if (!hasPartRevisionWriteAccess(user,partRev)) {
    throw new AccessRightException(locale,user);
  }
  DocumentLinkDAO linkDAO=new DocumentLinkDAO(locale,em);
  PartIteration partIte=partRev.getLastIteration();
  if (isCheckoutByUser(user,partRev) && partIte.getKey().equals(pKey)) {
    if (pLinkKeys != null) {
      Set<DocumentLink> currentLinks=new HashSet<>(partIte.getLinkedDocuments());
      for (      DocumentLink link : currentLinks) {
        partIte.getLinkedDocuments().remove(link);
      }
      int counter=0;
      for (      DocumentRevisionKey link : pLinkKeys) {
        DocumentLink newLink=new DocumentLink(em.getReference(DocumentRevision.class,link));
        newLink.setComment(documentLinkComments[counter]);
        linkDAO.createLink(newLink);
        partIte.getLinkedDocuments().add(newLink);
        counter++;
      }
    }
    if (pAttributes != null) {
      List<InstanceAttribute> currentAttrs=partRev.getLastIteration().getInstanceAttributes();
      boolean valid=AttributesConsistencyUtils.hasValidChange(pAttributes,partRev.isAttributesLocked(),currentAttrs);
      if (!valid) {
        throw new NotAllowedException(locale,"String_Node_Str");
      }
      partRev.getLastIteration().setInstanceAttributes(pAttributes);
    }
    if (pAttributeTemplates != null) {
      LOVDAO lovDAO=new LOVDAO(locale,em);
      List<InstanceAttributeTemplate> templateAttrs=new ArrayList<>();
      for (int i=0; i < pAttributeTemplates.size(); i++) {
        templateAttrs.add(pAttributeTemplates.get(i));
        if (pAttributeTemplates.get(i) instanceof ListOfValuesAttributeTemplate) {
          ListOfValuesAttributeTemplate lovAttr=(ListOfValuesAttributeTemplate)pAttributeTemplates.get(i);
          ListOfValuesKey lovKey=new ListOfValuesKey(user.getWorkspaceId(),lovNames[i]);
          lovAttr.setLov(lovDAO.loadLOV(lovKey));
        }
      }
      partIte.setInstanceAttributeTemplates(pAttributeTemplates);
    }
    if (pUsageLinks != null) {
      List<PartUsageLink> links=new ArrayList<>();
      for (      PartUsageLink usageLink : pUsageLinks) {
        PartUsageLink partUsageLink=findOrCreatePartLink(user,usageLink,partIte);
        links.add(partUsageLink);
      }
      partIte.setComponents(links);
      PartUsageLinkDAO partUsageLinkDAO=new PartUsageLinkDAO(new Locale(user.getLanguage()),em);
      partUsageLinkDAO.removeOrphanPartLinks();
      checkCyclicAssemblyForPartIteration(partIte);
    }
    partIte.setIterationNote(pIterationNote);
    partIte.setModificationDate(new Date());
    partIte.setSource(source);
  }
 else {
    throw new NotAllowedException(locale,"String_Node_Str");
  }
  return partRev;
}

Fixed version (ground truth):
@RolesAllowed(UserGroupMapping.REGULAR_USER_ROLE_ID) @Override public PartRevision updatePartIteration(PartIterationKey pKey,String pIterationNote,Source source,List<PartUsageLink> pUsageLinks,List<InstanceAttribute> pAttributes,List<InstanceAttributeTemplate> pAttributeTemplates,DocumentRevisionKey[] pLinkKeys,String[] documentLinkComments,String[] lovNames) throws UserNotFoundException, WorkspaceNotFoundException, AccessRightException, NotAllowedException, PartRevisionNotFoundException, PartMasterNotFoundException, EntityConstraintException, UserNotActiveException, ListOfValuesNotFoundException, PartUsageLinkNotFoundException {
  User user=userManager.checkWorkspaceWriteAccess(pKey.getWorkspaceId());
  Locale locale=new Locale(user.getLanguage());
  PartRevisionDAO partRDAO=new PartRevisionDAO(locale,em);
  PartRevision partRev=partRDAO.loadPartR(pKey.getPartRevision());
  if (!hasPartRevisionWriteAccess(user,partRev)) {
    throw new AccessRightException(locale,user);
  }
  DocumentLinkDAO linkDAO=new DocumentLinkDAO(locale,em);
  PartIteration partIte=partRev.getLastIteration();
  if (isCheckoutByUser(user,partRev) && partIte.getKey().equals(pKey)) {
    if (pLinkKeys != null) {
      Set<DocumentLink> currentLinks=new HashSet<>(partIte.getLinkedDocuments());
      for (      DocumentLink link : currentLinks) {
        partIte.getLinkedDocuments().remove(link);
      }
      int counter=0;
      for (      DocumentRevisionKey link : pLinkKeys) {
        DocumentLink newLink=new DocumentLink(em.getReference(DocumentRevision.class,link));
        newLink.setComment(documentLinkComments[counter]);
        linkDAO.createLink(newLink);
        partIte.getLinkedDocuments().add(newLink);
        counter++;
      }
    }
    if (pAttributes != null) {
      List<InstanceAttribute> currentAttrs=partRev.getLastIteration().getInstanceAttributes();
      boolean valid=AttributesConsistencyUtils.hasValidChange(pAttributes,partRev.isAttributesLocked(),currentAttrs);
      if (!valid) {
        throw new NotAllowedException(locale,"String_Node_Str");
      }
      partRev.getLastIteration().setInstanceAttributes(pAttributes);
    }
    if (pAttributeTemplates != null) {
      LOVDAO lovDAO=new LOVDAO(locale,em);
      List<InstanceAttributeTemplate> templateAttrs=new ArrayList<>();
      for (int i=0; i < pAttributeTemplates.size(); i++) {
        templateAttrs.add(pAttributeTemplates.get(i));
        if (pAttributeTemplates.get(i) instanceof ListOfValuesAttributeTemplate) {
          ListOfValuesAttributeTemplate lovAttr=(ListOfValuesAttributeTemplate)pAttributeTemplates.get(i);
          ListOfValuesKey lovKey=new ListOfValuesKey(user.getWorkspaceId(),lovNames[i]);
          lovAttr.setLov(lovDAO.loadLOV(lovKey));
        }
      }
      partIte.setInstanceAttributeTemplates(pAttributeTemplates);
    }
    if (pUsageLinks != null) {
      List<PartUsageLink> links=new ArrayList<>();
      for (      PartUsageLink usageLink : pUsageLinks) {
        PartUsageLink partUsageLink=findOrCreatePartLink(user,usageLink,partIte);
        links.add(partUsageLink);
      }
      partIte.setComponents(links);
      PartUsageLinkDAO partUsageLinkDAO=new PartUsageLinkDAO(new Locale(user.getLanguage()),em);
      partUsageLinkDAO.removeOrphanPartLinks();
      removeObsoletePathToPathLinks(user,pKey.getWorkspaceId());
      checkCyclicAssemblyForPartIteration(partIte);
    }
    partIte.setIterationNote(pIterationNote);
    partIte.setModificationDate(new Date());
    partIte.setSource(source);
  }
 else {
    throw new NotAllowedException(locale,"String_Node_Str");
  }
  return partRev;
}