Program: 113227
Project: 113227
Buggy source:
/** 
 * @param dagId
 * @param dag
 * @param nodeId
 * @param remove
 * @param dagDepth zero based depth of {@code dag} (not a depth index, which is{@code depth - 1}
 * @return
 */
private int put(final DAG dag,final NodeId nodeId,final boolean remove){
  checkNotNull(dag);
  checkNotNull(nodeId);
  final int dagDepth=dag.getId().depthLength();
  mergeRoot(dag,nodeId);
  boolean changed=false;
  final int deltaSize;
  final int normalizedSizeLimit=normalizedSizeLimit(dagDepth);
  if (dag.numBuckets() > 0) {
    final @Nullable TreeId bucketId=computeBucketId(nodeId,dagDepth + 1);
    if (bucketId != null) {
      DAG bucketDAG=getOrCreateDAG(bucketId);
      dag.addBucket(bucketId);
      deltaSize=put(bucketDAG,nodeId,remove);
      changed=bucketDAG.getState() == STATE.CHANGED;
      if (bucketDAG.getTotalChildCount() == 0) {
        dag.removeBucket(bucketId);
      }
    }
 else {
      deltaSize=0;
    }
  }
 else {
    if (remove) {
      deltaSize=dag.removeChild(nodeId) ? -1 : 0;
    }
 else {
      changed=true;
      deltaSize=dag.addChild(nodeId) ? +1 : 0;
    }
    final int size=dag.numChildren();
    if (size > normalizedSizeLimit) {
      ListMultimap<TreeId,NodeId> promotions=ArrayListMultimap.create();
      dag.forEachChild((childId) -> {
        TreeId bucketId=computeBucketId(childId,dagDepth + 1);
        checkNotNull(bucketId);
        promotions.put(bucketId,childId);
      }
);
      promotions.asMap().forEach((bucketId,childIds) -> {
        DAG bucketDAG=getOrCreateDAG(bucketId);
        dag.addBucket(bucketId);
        for (        NodeId childId : childIds) {
          put(bucketDAG,childId,remove);
        }
      }
);
      dag.clearChildren();
    }
  }
  if (deltaSize != 0) {
    changed=true;
    dag.setTotalChildCount(dag.getTotalChildCount() + deltaSize);
    shrinkIfUnderflow(dag,nodeId,dagDepth);
  }
  if (changed) {
    dag.setChanged();
  }
  return deltaSize;
}

Fixed version (ground truth):
/** 
 * @param dagId
 * @param dag
 * @param nodeId
 * @param remove
 * @param dagDepth zero based depth of {@code dag} (not a depth index, which is{@code depth - 1}
 * @return
 */
protected int put(final DAG dag,final NodeId nodeId,final boolean remove){
  checkNotNull(dag);
  checkNotNull(nodeId);
  final int dagDepth=dag.getId().depthLength();
  mergeRoot(dag);
  boolean changed=false;
  final int deltaSize;
  final int normalizedSizeLimit=normalizedSizeLimit(dagDepth);
  if (dag.numBuckets() > 0) {
    final @Nullable TreeId bucketId=computeBucketId(nodeId,dagDepth + 1);
    if (bucketId != null) {
      final DAG bucketDAG=getOrCreateDAG(bucketId);
      dag.addBucket(bucketId);
      deltaSize=put(bucketDAG,nodeId,remove);
      changed=bucketDAG.getState() == STATE.CHANGED;
      if (bucketDAG.getTotalChildCount() == 0) {
        dag.removeBucket(bucketId);
      }
    }
 else {
      deltaSize=0;
    }
  }
 else {
    if (remove) {
      final boolean removed=dag.removeChild(nodeId);
      deltaSize=removed ? -1 : 0;
    }
 else {
      changed=true;
      deltaSize=dag.addChild(nodeId) ? +1 : 0;
    }
    final int size=dag.numChildren();
    if (size > normalizedSizeLimit) {
      ListMultimap<TreeId,NodeId> promotions=ArrayListMultimap.create();
      dag.forEachChild((childId) -> {
        TreeId bucketId=computeBucketId(childId,dagDepth + 1);
        checkNotNull(bucketId);
        promotions.put(bucketId,childId);
      }
);
      promotions.asMap().forEach((bucketId,childIds) -> {
        DAG bucketDAG=getOrCreateDAG(bucketId);
        dag.addBucket(bucketId);
        for (        NodeId childId : childIds) {
          put(bucketDAG,childId,remove);
        }
      }
);
      dag.clearChildren();
    }
  }
  if (deltaSize != 0) {
    changed=true;
    dag.setTotalChildCount(dag.getTotalChildCount() + deltaSize);
    shrinkIfUnderflow(dag);
  }
  if (changed) {
    dag.setChanged();
  }
  return deltaSize;
}