Program: 171021
Project: 171021
Buggy source:
private void processCategoryChildren(AtlasGlossaryCategory newObj,AtlasGlossaryCategory existing,RelationshipOperation op) throws AtlasBaseException {
  Set<AtlasRelatedCategoryHeader> newChildren=newObj.getChildrenCategories();
  Set<AtlasRelatedCategoryHeader> existingChildren=existing.getChildrenCategories();
switch (op) {
case CREATE:
    if (DEBUG_ENABLED) {
      LOG.debug("String_Node_Str",existing.getDisplayName(),Objects.nonNull(newChildren) ? newChildren.size() : "String_Node_Str");
    }
  createCategoryRelationships(existing,newChildren);
break;
case UPDATE:
if (CollectionUtils.isEmpty(existingChildren)) {
if (DEBUG_ENABLED) {
  LOG.debug("String_Node_Str",existing.getDisplayName(),Objects.nonNull(newChildren) ? newChildren.size() : "String_Node_Str");
}
createCategoryRelationships(existing,newChildren);
break;
}
if (CollectionUtils.isEmpty(newChildren)) {
if (DEBUG_ENABLED) {
LOG.debug("String_Node_Str",existing.getDisplayName(),existingChildren.size());
}
deleteCategoryRelationships(existing,existingChildren);
break;
}
Set<AtlasRelatedCategoryHeader> toCreate=newChildren.stream().filter(c -> Objects.isNull(c.getRelationGuid())).collect(Collectors.toSet());
createCategoryRelationships(existing,toCreate);
Set<AtlasRelatedCategoryHeader> toUpdate=newChildren.stream().filter(c -> Objects.nonNull(c.getRelationGuid()) && existingChildren.contains(c)).collect(Collectors.toSet());
updateCategoryRelationships(existing,toUpdate);
Set<AtlasRelatedCategoryHeader> toDelete=existingChildren.stream().filter(c -> !toCreate.contains(c) && !toUpdate.contains(c)).collect(Collectors.toSet());
deleteCategoryRelationships(existing,toDelete);
break;
case DELETE:
deleteCategoryRelationships(existing,existingChildren);
break;
}
}

Fixed version (ground truth):
private void processCategoryChildren(AtlasGlossaryCategory updatedCategory,AtlasGlossaryCategory existing,RelationshipOperation op) throws AtlasBaseException {
  Map<String,AtlasRelatedCategoryHeader> newChildren=getChildren(updatedCategory);
  Map<String,AtlasRelatedCategoryHeader> existingChildren=getChildren(existing);
switch (op) {
case CREATE:
    if (DEBUG_ENABLED) {
      LOG.debug("String_Node_Str",existing.getDisplayName(),Objects.nonNull(newChildren) ? newChildren.size() : "String_Node_Str");
    }
  createCategoryRelationships(existing,newChildren.values());
break;
case UPDATE:
if (MapUtils.isEmpty(existingChildren)) {
if (DEBUG_ENABLED) {
  LOG.debug("String_Node_Str",existing.getDisplayName(),Objects.nonNull(newChildren) ? newChildren.size() : "String_Node_Str");
}
createCategoryRelationships(existing,newChildren.values());
break;
}
if (MapUtils.isEmpty(newChildren)) {
if (DEBUG_ENABLED) {
LOG.debug("String_Node_Str",existing.getDisplayName(),existingChildren.size());
}
deleteCategoryRelationships(existing,existingChildren.values());
break;
}
Set<AtlasRelatedCategoryHeader> toCreate=newChildren.values().stream().filter(c -> !existingChildren.containsKey(c.getCategoryGuid())).collect(Collectors.toSet());
createCategoryRelationships(existing,toCreate);
Set<AtlasRelatedCategoryHeader> toUpdate=newChildren.values().stream().filter(c -> updatedExistingCategoryRelation(existingChildren,c)).collect(Collectors.toSet());
updateCategoryRelationships(existing,toUpdate);
Set<AtlasRelatedCategoryHeader> toDelete=existingChildren.values().stream().filter(c -> !newChildren.containsKey(c.getCategoryGuid())).collect(Collectors.toSet());
deleteCategoryRelationships(existing,toDelete);
break;
case DELETE:
deleteCategoryRelationships(existing,existingChildren.values());
break;
}
}