Program: 86061
Project: 86061
Buggy source:
@RolesAllowed("String_Node_Str") @Override public PartRevision updatePartIteration(PartIterationKey pKey,String pIterationNote,Source source,List<PartUsageLink> pUsageLinks,List<InstanceAttribute> pAttributes) throws UserNotFoundException, WorkspaceNotFoundException, AccessRightException, NotAllowedException, PartRevisionNotFoundException {
  User user=userManager.checkWorkspaceWriteAccess(pKey.getWorkspaceId());
  PartRevisionDAO partRDAO=new PartRevisionDAO(new Locale(user.getLanguage()),em);
  PartRevision partRev=partRDAO.loadPartR(pKey.getPartRevision());
  PartIteration partIte=partRev.getLastIteration();
  if (partRev.isCheckedOut() && partRev.getCheckOutUser().equals(user) && partIte.getKey().equals(pKey)) {
    partIte.setComponents(pUsageLinks);
    Map<String,InstanceAttribute> attrs=new HashMap<String,InstanceAttribute>();
    for (    InstanceAttribute attr : pAttributes) {
      attrs.put(attr.getName(),attr);
    }
    Set<InstanceAttribute> currentAttrs=new HashSet<InstanceAttribute>(partIte.getInstanceAttributes().values());
    for (    InstanceAttribute attr : currentAttrs) {
      if (!attrs.containsKey(attr.getName())) {
        partIte.getInstanceAttributes().remove(attr.getName());
      }
    }
    for (    InstanceAttribute attr : attrs.values()) {
      if (!partIte.getInstanceAttributes().containsKey(attr.getName())) {
        partIte.getInstanceAttributes().put(attr.getName(),attr);
      }
 else {
        partIte.getInstanceAttributes().get(attr.getName()).setValue(attr.getValue());
      }
    }
    partIte.setIterationNote(pIterationNote);
    partIte.setSource(source);
    return partRev;
  }
 else {
    throw new NotAllowedException(new Locale(user.getLanguage()),"String_Node_Str");
  }
}

Fixed version (ground truth):
@RolesAllowed("String_Node_Str") @Override public PartRevision updatePartIteration(PartIterationKey pKey,String pIterationNote,Source source,List<PartUsageLink> pUsageLinks,List<InstanceAttribute> pAttributes) throws UserNotFoundException, WorkspaceNotFoundException, AccessRightException, NotAllowedException, PartRevisionNotFoundException, PartMasterNotFoundException {
  User user=userManager.checkWorkspaceWriteAccess(pKey.getWorkspaceId());
  PartMasterDAO partMDAO=new PartMasterDAO(new Locale(user.getLanguage()),em);
  PartRevisionDAO partRDAO=new PartRevisionDAO(new Locale(user.getLanguage()),em);
  PartRevision partRev=partRDAO.loadPartR(pKey.getPartRevision());
  PartIteration partIte=partRev.getLastIteration();
  if (partRev.isCheckedOut() && partRev.getCheckOutUser().equals(user) && partIte.getKey().equals(pKey)) {
    List<PartUsageLink> usageLinks=new LinkedList<PartUsageLink>();
    for (    PartUsageLink usageLink : pUsageLinks) {
      PartUsageLink ul=new PartUsageLink();
      ul.setAmount(usageLink.getAmount());
      ul.setCadInstances(usageLink.getCadInstances());
      ul.setComment(usageLink.getComment());
      ul.setReferenceDescription(usageLink.getReferenceDescription());
      ul.setUnit(usageLink.getUnit());
      PartMaster pm=usageLink.getComponent();
      PartMaster component=partMDAO.loadPartM(new PartMasterKey(pm.getWorkspaceId(),pm.getNumber()));
      ul.setComponent(component);
      List<PartSubstituteLink> substitutes=new LinkedList<PartSubstituteLink>();
      for (      PartSubstituteLink substitute : usageLink.getSubstitutes()) {
        PartSubstituteLink sub=new PartSubstituteLink();
        sub.setCadInstances(substitute.getCadInstances());
        sub.setComment(substitute.getComment());
        sub.setReferenceDescription(substitute.getReferenceDescription());
        PartMaster pmSub=substitute.getSubstitute();
        sub.setSubstitute(partMDAO.loadPartM(new PartMasterKey(pmSub.getWorkspaceId(),pmSub.getNumber())));
        substitutes.add(sub);
      }
      ul.setSubstitutes(substitutes);
      usageLinks.add(ul);
    }
    partIte.setComponents(usageLinks);
    Map<String,InstanceAttribute> attrs=new HashMap<String,InstanceAttribute>();
    for (    InstanceAttribute attr : pAttributes) {
      attrs.put(attr.getName(),attr);
    }
    Set<InstanceAttribute> currentAttrs=new HashSet<InstanceAttribute>(partIte.getInstanceAttributes().values());
    for (    InstanceAttribute attr : currentAttrs) {
      if (!attrs.containsKey(attr.getName())) {
        partIte.getInstanceAttributes().remove(attr.getName());
      }
    }
    for (    InstanceAttribute attr : attrs.values()) {
      if (!partIte.getInstanceAttributes().containsKey(attr.getName())) {
        partIte.getInstanceAttributes().put(attr.getName(),attr);
      }
 else {
        partIte.getInstanceAttributes().get(attr.getName()).setValue(attr.getValue());
      }
    }
    partIte.setIterationNote(pIterationNote);
    partIte.setSource(source);
    return partRev;
  }
 else {
    throw new NotAllowedException(new Locale(user.getLanguage()),"String_Node_Str");
  }
}