Program: 166942
Project: 166942
Buggy source:
void combineSteps(Traversal.Admin<?,?> traversal,List<Step> steps,ListIterator<Step> stepIterator){
  SqlgStep sqlgStep=null;
  Step previous=null;
  ReplacedStep<?,?> lastReplacedStep=null;
  int pathCount=0;
  boolean alreadyReplacedGraphStep=false;
  boolean repeatStepAdded;
  boolean chooseStepAdded=false;
  MutableInt repeatStepsAdded=new MutableInt(0);
  while (stepIterator.hasNext()) {
    Step step=stepIterator.next();
    if (step instanceof RepeatStep) {
      try {
        repeatStepAdded=flattenRepeatStep(steps,stepIterator,(RepeatStep)step,traversal,repeatStepsAdded);
        if (this instanceof SqlgVertexStepStrategy && !repeatStepAdded) {
          traversal.addStep(new IdentityStep<>(traversal));
        }
      }
 catch (      UnoptimizableException e) {
        lastReplacedStep.addLabel((pathCount) + BaseSqlgStrategy.PATH_LABEL_SUFFIX + BaseSqlgStrategy.SQLG_PATH_FAKE_LABEL);
        return;
      }
    }
 else     if (step instanceof ChooseStep) {
      try {
        chooseStepAdded=flattenChooseStep(steps,stepIterator,(ChooseStep)step,traversal);
      }
 catch (      UnoptimizableException e) {
        return;
      }
    }
 else {
      if (isReplaceableStep(step.getClass(),alreadyReplacedGraphStep)) {
        boolean emit=false;
        boolean emitFirst=false;
        boolean untilFirst=false;
        Set<String> labels=new HashSet<>();
        if (repeatStepsAdded.getValue() > 0) {
          repeatStepsAdded.decrement();
          RepeatStep repeatStep=(RepeatStep)step.getTraversal().getParent();
          emit=repeatStep.getEmitTraversal() != null;
          emitFirst=repeatStep.emitFirst;
          untilFirst=repeatStep.untilFirst;
          labels.addAll(repeatStep.getLabels());
        }
        pathCount++;
        @SuppressWarnings("String_Node_Str") ReplacedStep replacedStep=ReplacedStep.from(((SqlgGraph)traversal.getGraph().get()).getTopology(),(AbstractStep)step,pathCount);
        if (sqlgStep == null || step instanceof GraphStep) {
          sqlgStep=constructSqlgStep(traversal,step);
          if (previous != null) {
            sqlgStep.setPreviousStep(previous);
          }
          alreadyReplacedGraphStep=alreadyReplacedGraphStep || step instanceof GraphStep;
          if (this instanceof SqlgGraphStepStrategy) {
            sqlgStep.addReplacedStep(replacedStep);
          }
 else           if (this instanceof SqlgVertexStepStrategy) {
            previous=step;
          }
 else {
            throw new IllegalStateException("String_Node_Str" + this.getClass().getName());
          }
          replaceStepInTraversal(step,sqlgStep,traversal);
          if (sqlgStep instanceof SqlgGraphStepCompiled && ((SqlgGraphStepCompiled)sqlgStep).getIds().length > 0) {
            addHasContainerForIds((SqlgGraphStepCompiled)sqlgStep,replacedStep);
          }
          collectHasSteps(stepIterator,traversal,replacedStep,pathCount);
        }
        if (emit) {
          List<ReplacedStep> previousReplacedSteps=sqlgStep.getReplacedSteps();
          ReplacedStep previousReplacedStep;
          if (emitFirst) {
            previousReplacedStep=previousReplacedSteps.get(previousReplacedSteps.size() - 1);
            pathCount--;
          }
 else {
            previousReplacedStep=replacedStep;
          }
          previousReplacedStep.setEmit(true);
          previousReplacedStep.setUntilFirst(untilFirst);
          if (labels.isEmpty()) {
            previousReplacedStep.addLabel(pathCount + BaseSqlgStrategy.EMIT_LABEL_SUFFIX + BaseSqlgStrategy.SQLG_PATH_FAKE_LABEL);
          }
 else {
            for (            String label : labels) {
              previousReplacedStep.addLabel(pathCount + BaseSqlgStrategy.EMIT_LABEL_SUFFIX + label);
            }
          }
          previousReplacedStep.getLabels().remove(pathCount + BaseSqlgStrategy.PATH_LABEL_SUFFIX + BaseSqlgStrategy.SQLG_PATH_FAKE_LABEL);
          if (emitFirst) {
            pathCount++;
          }
        }
        if (chooseStepAdded) {
          pathCount--;
          List<ReplacedStep> previousReplacedSteps=sqlgStep.getReplacedSteps();
          ReplacedStep previousReplacedStep=previousReplacedSteps.get(previousReplacedSteps.size() - 1);
          previousReplacedStep.setLeftJoin(true);
          previousReplacedStep.getLabels().remove(pathCount + BaseSqlgStrategy.PATH_LABEL_SUFFIX + BaseSqlgStrategy.SQLG_PATH_FAKE_LABEL);
          previousReplacedStep.addLabel(pathCount + BaseSqlgStrategy.PATH_LABEL_SUFFIX + BaseSqlgStrategy.SQLG_PATH_FAKE_LABEL);
          pathCount++;
        }
        if (replacedStep.getLabels().isEmpty()) {
          boolean precedesPathStep=precedesPathOrTreeStep(traversal);
          if (precedesPathStep) {
            replacedStep.addLabel(pathCount + BaseSqlgStrategy.PATH_LABEL_SUFFIX + BaseSqlgStrategy.SQLG_PATH_FAKE_LABEL);
          }
        }
        if (previous != null && !(step instanceof GraphStep)) {
          sqlgStep.addReplacedStep(replacedStep);
          int index=TraversalHelper.stepIndex(step,traversal);
          if (index != -1) {
            traversal.removeStep(step);
          }
          collectHasSteps(stepIterator,traversal,replacedStep,pathCount);
        }
        previous=step;
        lastReplacedStep=replacedStep;
        chooseStepAdded=false;
      }
 else {
        if (lastReplacedStep != null) {
          boolean doLastEntry=step instanceof OrderGlobalStep || step instanceof RangeGlobalStep;
          if (!doLastEntry && (step instanceof SelectStep || step instanceof SelectOneStep || step instanceof EmptyStep) && stepIterator.hasNext()) {
            Step<?,?> nextStep=stepIterator.next();
            doLastEntry=nextStep instanceof OrderGlobalStep || nextStep instanceof RangeGlobalStep;
            stepIterator.previous();
          }
          if (doLastEntry) {
            doLastEntry(step,stepIterator,traversal,lastReplacedStep,sqlgStep);
          }
        }
        break;
      }
    }
  }
  if (lastReplacedStep != null && !lastReplacedStep.isEmit() && lastReplacedStep.getLabels().isEmpty()) {
    lastReplacedStep.addLabel((pathCount) + BaseSqlgStrategy.PATH_LABEL_SUFFIX + BaseSqlgStrategy.SQLG_PATH_FAKE_LABEL);
  }
}

Fixed version (ground truth):
void combineSteps(Traversal.Admin<?,?> traversal,List<Step> steps,ListIterator<Step> stepIterator){
  SqlgStep sqlgStep=null;
  Step previous=null;
  ReplacedStep<?,?> lastReplacedStep=null;
  int pathCount=0;
  boolean alreadyReplacedGraphStep=false;
  boolean repeatStepAdded;
  boolean chooseStepAdded=false;
  MutableInt repeatStepsAdded=new MutableInt(0);
  while (stepIterator.hasNext()) {
    Step step=stepIterator.next();
    if (step instanceof RepeatStep) {
      try {
        repeatStepAdded=flattenRepeatStep(steps,stepIterator,(RepeatStep)step,traversal,repeatStepsAdded);
        if (this instanceof SqlgVertexStepStrategy && !repeatStepAdded) {
          traversal.addStep(new IdentityStep<>(traversal));
        }
      }
 catch (      UnoptimizableException e) {
        lastReplacedStep.addLabel((pathCount) + BaseSqlgStrategy.PATH_LABEL_SUFFIX + BaseSqlgStrategy.SQLG_PATH_FAKE_LABEL);
        return;
      }
    }
 else     if (step instanceof ChooseStep) {
      try {
        chooseStepAdded=flattenChooseStep(steps,stepIterator,(ChooseStep)step,traversal);
      }
 catch (      UnoptimizableException e) {
        return;
      }
    }
 else {
      if (isReplaceableStep(step.getClass(),alreadyReplacedGraphStep)) {
        boolean emit=false;
        boolean emitFirst=false;
        boolean untilFirst=false;
        Set<String> labels=new HashSet<>();
        if (repeatStepsAdded.getValue() > 0) {
          repeatStepsAdded.decrement();
          RepeatStep repeatStep=(RepeatStep)step.getTraversal().getParent();
          emit=repeatStep.getEmitTraversal() != null;
          emitFirst=repeatStep.emitFirst;
          untilFirst=repeatStep.untilFirst;
          labels.addAll(repeatStep.getLabels());
        }
        pathCount++;
        @SuppressWarnings("String_Node_Str") ReplacedStep replacedStep=ReplacedStep.from(((SqlgGraph)traversal.getGraph().get()).getTopology(),(AbstractStep)step,pathCount);
        if (sqlgStep == null || step instanceof GraphStep) {
          sqlgStep=constructSqlgStep(traversal,step);
          if (previous != null) {
            sqlgStep.setPreviousStep(previous);
          }
          alreadyReplacedGraphStep=alreadyReplacedGraphStep || step instanceof GraphStep;
          if (this instanceof SqlgGraphStepStrategy) {
            sqlgStep.addReplacedStep(replacedStep);
          }
 else           if (this instanceof SqlgVertexStepStrategy) {
            previous=step;
          }
 else {
            throw new IllegalStateException("String_Node_Str" + this.getClass().getName());
          }
          replaceStepInTraversal(step,sqlgStep,traversal);
          if (sqlgStep instanceof SqlgGraphStepCompiled && ((SqlgGraphStepCompiled)sqlgStep).getIds().length > 0) {
            addHasContainerForIds((SqlgGraphStepCompiled)sqlgStep,replacedStep);
          }
          collectHasSteps(stepIterator,traversal,replacedStep,pathCount);
        }
        if (emit) {
          List<ReplacedStep> previousReplacedSteps=sqlgStep.getReplacedSteps();
          ReplacedStep previousReplacedStep;
          if (emitFirst) {
            previousReplacedStep=previousReplacedSteps.get(previousReplacedSteps.size() - 1);
            pathCount--;
          }
 else {
            previousReplacedStep=replacedStep;
          }
          previousReplacedStep.setEmit(true);
          previousReplacedStep.setUntilFirst(untilFirst);
          if (labels.isEmpty()) {
            previousReplacedStep.addLabel(pathCount + BaseSqlgStrategy.EMIT_LABEL_SUFFIX + BaseSqlgStrategy.SQLG_PATH_FAKE_LABEL);
          }
 else {
            for (            String label : labels) {
              previousReplacedStep.addLabel(pathCount + BaseSqlgStrategy.EMIT_LABEL_SUFFIX + label);
            }
          }
          previousReplacedStep.getLabels().remove(pathCount + BaseSqlgStrategy.PATH_LABEL_SUFFIX + BaseSqlgStrategy.SQLG_PATH_FAKE_LABEL);
          if (emitFirst) {
            pathCount++;
          }
        }
        if (chooseStepAdded) {
          pathCount--;
          List<ReplacedStep> previousReplacedSteps=sqlgStep.getReplacedSteps();
          ReplacedStep previousReplacedStep=previousReplacedSteps.get(previousReplacedSteps.size() - 1);
          previousReplacedStep.setLeftJoin(true);
          previousReplacedStep.getLabels().remove(pathCount + BaseSqlgStrategy.PATH_LABEL_SUFFIX + BaseSqlgStrategy.SQLG_PATH_FAKE_LABEL);
          previousReplacedStep.addLabel(pathCount + BaseSqlgStrategy.PATH_LABEL_SUFFIX + BaseSqlgStrategy.SQLG_PATH_FAKE_LABEL);
          pathCount++;
        }
        if (replacedStep.getLabels().isEmpty()) {
          boolean precedesPathStep=precedesPathOrTreeStep(traversal);
          if (precedesPathStep) {
            replacedStep.addLabel(pathCount + BaseSqlgStrategy.PATH_LABEL_SUFFIX + BaseSqlgStrategy.SQLG_PATH_FAKE_LABEL);
          }
        }
        if (previous != null && !(step instanceof GraphStep)) {
          sqlgStep.addReplacedStep(replacedStep);
          int index=TraversalHelper.stepIndex(step,traversal);
          if (index != -1) {
            traversal.removeStep(step);
          }
          collectHasSteps(stepIterator,traversal,replacedStep,pathCount);
        }
        previous=step;
        lastReplacedStep=replacedStep;
        chooseStepAdded=false;
      }
 else {
        if (lastReplacedStep != null) {
          boolean doLastEntry=step instanceof OrderGlobalStep || step instanceof RangeGlobalStep;
          if (!doLastEntry && (step instanceof SelectStep || step instanceof SelectOneStep || step instanceof EmptyStep) && stepIterator.hasNext()) {
            Step<?,?> nextStep=stepIterator.next();
            doLastEntry=nextStep instanceof OrderGlobalStep || nextStep instanceof RangeGlobalStep;
            stepIterator.previous();
          }
          if (doLastEntry) {
            doLastEntry(step,stepIterator,traversal,lastReplacedStep,sqlgStep,pathCount);
          }
        }
        break;
      }
    }
  }
  if (lastReplacedStep != null && !lastReplacedStep.isEmit() && lastReplacedStep.getLabels().isEmpty()) {
    lastReplacedStep.addLabel((pathCount) + BaseSqlgStrategy.PATH_LABEL_SUFFIX + BaseSqlgStrategy.SQLG_PATH_FAKE_LABEL);
  }
}