Program: 171026
Project: 171026
Buggy source:
private void processAssociatedTerms(AtlasGlossaryCategory newObj,AtlasGlossaryCategory existing,RelationshipOperation op) throws AtlasBaseException {
  Set<AtlasRelatedTermHeader> newTerms=newObj.getTerms();
  Set<AtlasRelatedTermHeader> existingTerms=existing.getTerms();
switch (op) {
case CREATE:
    if (DEBUG_ENABLED) {
      LOG.debug("String_Node_Str",existing.getDisplayName(),Objects.nonNull(newTerms) ? newTerms.size() : "String_Node_Str");
    }
  createTermCategorizationRelationships(existing,newTerms);
break;
case UPDATE:
if (CollectionUtils.isEmpty(existingTerms)) {
if (DEBUG_ENABLED) {
  LOG.debug("String_Node_Str",existing.getDisplayName(),Objects.nonNull(newTerms) ? newTerms.size() : "String_Node_Str");
}
createTermCategorizationRelationships(existing,newTerms);
break;
}
if (CollectionUtils.isEmpty(newTerms)) {
if (DEBUG_ENABLED) {
LOG.debug("String_Node_Str",existing.getDisplayName(),existingTerms.size());
}
deleteTermCategorizationRelationships(existing,existingTerms);
break;
}
Set<AtlasRelatedTermHeader> toCreate=newTerms.stream().filter(c -> Objects.isNull(c.getRelationGuid())).collect(Collectors.toSet());
createTermCategorizationRelationships(existing,toCreate);
Set<AtlasRelatedTermHeader> toUpdate=newTerms.stream().filter(c -> Objects.nonNull(c.getRelationGuid()) && existingTerms.contains(c)).collect(Collectors.toSet());
updateTermCategorizationRelationships(existing,toUpdate);
Set<AtlasRelatedTermHeader> toDelete=existingTerms.stream().filter(c -> !toCreate.contains(c) && !toUpdate.contains(c)).collect(Collectors.toSet());
deleteTermCategorizationRelationships(existing,toDelete);
break;
case DELETE:
deleteTermCategorizationRelationships(existing,existingTerms);
break;
}
}

Fixed version (ground truth):
private void processAssociatedTerms(AtlasGlossaryCategory updatedCategory,AtlasGlossaryCategory existing,RelationshipOperation op) throws AtlasBaseException {
  Map<String,AtlasRelatedTermHeader> newTerms=getTerms(updatedCategory);
  Map<String,AtlasRelatedTermHeader> existingTerms=getTerms(existing);
switch (op) {
case CREATE:
    if (DEBUG_ENABLED) {
      LOG.debug("String_Node_Str",existing.getDisplayName(),Objects.nonNull(newTerms) ? newTerms.size() : "String_Node_Str");
    }
  createTermCategorizationRelationships(existing,newTerms.values());
break;
case UPDATE:
if (MapUtils.isEmpty(existingTerms)) {
if (DEBUG_ENABLED) {
  LOG.debug("String_Node_Str",existing.getDisplayName(),Objects.nonNull(newTerms) ? newTerms.size() : "String_Node_Str");
}
createTermCategorizationRelationships(existing,newTerms.values());
break;
}
if (MapUtils.isEmpty(newTerms)) {
if (DEBUG_ENABLED) {
LOG.debug("String_Node_Str",existing.getDisplayName(),existingTerms.size());
}
deleteTermCategorizationRelationships(existing,existingTerms.values());
break;
}
Set<AtlasRelatedTermHeader> toCreate=newTerms.values().stream().filter(t -> !existingTerms.containsKey(t.getTermGuid())).collect(Collectors.toSet());
createTermCategorizationRelationships(existing,toCreate);
Set<AtlasRelatedTermHeader> toUpdate=newTerms.values().stream().filter(t -> updatedExistingTermRelation(existingTerms,t)).collect(Collectors.toSet());
updateTermCategorizationRelationships(existing,toUpdate);
Set<AtlasRelatedTermHeader> toDelete=existingTerms.values().stream().filter(t -> !newTerms.containsKey(t.getTermGuid())).collect(Collectors.toSet());
deleteTermCategorizationRelationships(existing,toDelete);
break;
case DELETE:
deleteTermCategorizationRelationships(existing,existingTerms.values());
break;
}
}