Program: 167068
Project: 167068
Buggy source:
@Override public void apply(final Traversal.Admin<?,?> traversal){
  final Step<?,?> startStep=traversal.getStartStep();
  if (!(startStep instanceof GraphStep)) {
    return;
  }
  final GraphStep<?> originalGraphStep=(GraphStep)startStep;
  final List<Step> steps=new ArrayList<>(traversal.asAdmin().getSteps());
  final ListIterator<Step> stepIterator=steps.listIterator();
  if (originalGraphStep.getIds().length > 0) {
    return;
  }
  if (this.canNotBeOptimized(steps,stepIterator.nextIndex())) {
    logger.debug("String_Node_Str" + traversal.toString() + "String_Node_Str"+ ExceptionUtils.getStackTrace(new Throwable()));
    return;
  }
  if (unoptimizableRepeat(steps,stepIterator.nextIndex())) {
    logger.debug("String_Node_Str" + traversal.toString() + "String_Node_Str"+ ExceptionUtils.getStackTrace(new Throwable()));
    return;
  }
  SqlgGraphStepCompiled sqlgGraphStepCompiled=null;
  Step previous=null;
  ReplacedStep<?,?> lastReplacedStep=null;
  int pathCount=0;
  boolean repeatStepAdded=false;
  int repeatStepsAdded=0;
  while (stepIterator.hasNext()) {
    Step step=stepIterator.next();
    if (step instanceof RepeatStep) {
      repeatStepsAdded=0;
      repeatStepAdded=false;
      RepeatStep repeatStep=(RepeatStep)step;
      List<Traversal.Admin<?,?>> repeatTraversals=repeatStep.getGlobalChildren();
      Traversal.Admin admin=repeatTraversals.get(0);
      List<Step> internalRepeatSteps=admin.getSteps();
      LoopTraversal loopTraversal=(LoopTraversal)repeatStep.getUntilTraversal();
      long numberOfLoops=loopTraversal.getMaxLoops();
      for (int i=0; i < numberOfLoops; i++) {
        for (        Step internalRepeatStep : internalRepeatSteps) {
          if (internalRepeatStep instanceof RepeatStep.RepeatEndStep) {
            break;
          }
          stepIterator.add(internalRepeatStep);
          stepIterator.previous();
          stepIterator.next();
          repeatStepAdded=true;
          repeatStepsAdded++;
        }
      }
      traversal.removeStep(repeatStep);
      for (int i=0; i < repeatStepsAdded; i++) {
        stepIterator.previous();
      }
    }
 else {
      if (CONSECUTIVE_STEPS_TO_REPLACE.contains(step.getClass())) {
        boolean emit=false;
        boolean emitFirst=false;
        boolean untilFirst=false;
        if (repeatStepsAdded > 0) {
          repeatStepsAdded--;
          RepeatStep repeatStep=(RepeatStep)step.getTraversal().getParent();
          emit=repeatStep.getEmitTraversal() != null;
          emitFirst=repeatStep.emitFirst;
          untilFirst=repeatStep.untilFirst;
        }
        pathCount++;
        ReplacedStep replacedStep=ReplacedStep.from(this.sqlgGraph.getSchemaManager(),(AbstractStep)step,pathCount);
        if (emit) {
          List<ReplacedStep> previousReplacedSteps=sqlgGraphStepCompiled.getReplacedSteps();
          ReplacedStep previousReplacedStep;
          if (emitFirst) {
            previousReplacedStep=previousReplacedSteps.get(previousReplacedSteps.size() - 1);
          }
 else {
            previousReplacedStep=replacedStep;
          }
          previousReplacedStep.setEmit(true);
          previousReplacedStep.setUntilFirst(untilFirst);
          previousReplacedStep.addLabel((pathCount - 1) + BaseSqlgStrategy.EMIT_LABEL_SUFFIX + BaseSqlgStrategy.SQLG_PATH_FAKE_LABEL);
          previousReplacedStep.getLabels().remove((pathCount - 1) + BaseSqlgStrategy.PATH_LABEL_SUFFIX + BaseSqlgStrategy.SQLG_PATH_FAKE_LABEL);
        }
        if (replacedStep.getLabels().isEmpty()) {
          boolean precedesPathStep=precedesPathOrTreeStep(steps,stepIterator.nextIndex());
          if (precedesPathStep) {
            replacedStep.addLabel(pathCount + BaseSqlgStrategy.PATH_LABEL_SUFFIX + BaseSqlgStrategy.SQLG_PATH_FAKE_LABEL);
          }
        }
        if (previous == null) {
          sqlgGraphStepCompiled=new SqlgGraphStepCompiled(this.sqlgGraph,traversal,originalGraphStep.getReturnClass(),originalGraphStep.getIds());
          sqlgGraphStepCompiled.addReplacedStep(replacedStep);
          TraversalHelper.replaceStep(step,sqlgGraphStepCompiled,traversal);
          collectHasSteps(stepIterator,traversal,replacedStep,pathCount);
        }
 else {
          sqlgGraphStepCompiled.addReplacedStep(replacedStep);
          if (!repeatStepAdded) {
            traversal.removeStep(step);
          }
          collectHasSteps(stepIterator,traversal,replacedStep,pathCount);
        }
        previous=step;
        lastReplacedStep=replacedStep;
      }
 else {
        if (lastReplacedStep != null) {
          sqlgGraphStepCompiled.parseForStrategy();
          if (!sqlgGraphStepCompiled.isForMultipleQueries()) {
            collectOrderGlobalSteps(step,stepIterator,traversal,lastReplacedStep);
          }
        }
        break;
      }
    }
  }
}

Fixed version (ground truth):
@Override public void apply(final Traversal.Admin<?,?> traversal){
  final Step<?,?> startStep=traversal.getStartStep();
  if (!(startStep instanceof GraphStep)) {
    return;
  }
  final GraphStep<?> originalGraphStep=(GraphStep)startStep;
  final List<Step> steps=new ArrayList<>(traversal.asAdmin().getSteps());
  final ListIterator<Step> stepIterator=steps.listIterator();
  if (originalGraphStep.getIds().length > 0) {
    return;
  }
  if (this.canNotBeOptimized(steps,stepIterator.nextIndex())) {
    logger.debug("String_Node_Str" + traversal.toString() + "String_Node_Str"+ ExceptionUtils.getStackTrace(new Throwable()));
    return;
  }
  if (unoptimizableRepeat(steps,stepIterator.nextIndex())) {
    logger.debug("String_Node_Str" + traversal.toString() + "String_Node_Str"+ ExceptionUtils.getStackTrace(new Throwable()));
    return;
  }
  SqlgGraphStepCompiled sqlgGraphStepCompiled=null;
  Step previous=null;
  ReplacedStep<?,?> lastReplacedStep=null;
  int pathCount=0;
  boolean repeatStepAdded=false;
  int repeatStepsAdded=0;
  while (stepIterator.hasNext()) {
    Step step=stepIterator.next();
    if (step instanceof RepeatStep) {
      repeatStepsAdded=0;
      repeatStepAdded=false;
      RepeatStep repeatStep=(RepeatStep)step;
      List<Traversal.Admin<?,?>> repeatTraversals=repeatStep.getGlobalChildren();
      Traversal.Admin admin=repeatTraversals.get(0);
      List<Step> internalRepeatSteps=admin.getSteps();
      LoopTraversal loopTraversal=(LoopTraversal)repeatStep.getUntilTraversal();
      long numberOfLoops=loopTraversal.getMaxLoops();
      for (int i=0; i < numberOfLoops; i++) {
        for (        Step internalRepeatStep : internalRepeatSteps) {
          if (internalRepeatStep instanceof RepeatStep.RepeatEndStep) {
            break;
          }
          stepIterator.add(internalRepeatStep);
          stepIterator.previous();
          stepIterator.next();
          repeatStepAdded=true;
          repeatStepsAdded++;
        }
      }
      traversal.removeStep(repeatStep);
      for (int i=0; i < repeatStepsAdded; i++) {
        stepIterator.previous();
      }
    }
 else {
      if (CONSECUTIVE_STEPS_TO_REPLACE.contains(step.getClass())) {
        boolean emit=false;
        boolean emitFirst=false;
        boolean untilFirst=false;
        if (repeatStepsAdded > 0) {
          repeatStepsAdded--;
          RepeatStep repeatStep=(RepeatStep)step.getTraversal().getParent();
          emit=repeatStep.getEmitTraversal() != null;
          emitFirst=repeatStep.emitFirst;
          untilFirst=repeatStep.untilFirst;
        }
        pathCount++;
        ReplacedStep replacedStep=ReplacedStep.from(this.sqlgGraph.getSchemaManager(),(AbstractStep)step,pathCount);
        if (emit) {
          List<ReplacedStep> previousReplacedSteps=sqlgGraphStepCompiled.getReplacedSteps();
          ReplacedStep previousReplacedStep;
          if (emitFirst) {
            previousReplacedStep=previousReplacedSteps.get(previousReplacedSteps.size() - 1);
            pathCount--;
          }
 else {
            previousReplacedStep=replacedStep;
          }
          previousReplacedStep.setEmit(true);
          previousReplacedStep.setUntilFirst(untilFirst);
          previousReplacedStep.addLabel((pathCount) + BaseSqlgStrategy.EMIT_LABEL_SUFFIX + BaseSqlgStrategy.SQLG_PATH_FAKE_LABEL);
          previousReplacedStep.getLabels().remove((pathCount) + BaseSqlgStrategy.PATH_LABEL_SUFFIX + BaseSqlgStrategy.SQLG_PATH_FAKE_LABEL);
        }
        if (replacedStep.getLabels().isEmpty()) {
          boolean precedesPathStep=precedesPathOrTreeStep(steps,stepIterator.nextIndex());
          if (precedesPathStep) {
            replacedStep.addLabel(pathCount + BaseSqlgStrategy.PATH_LABEL_SUFFIX + BaseSqlgStrategy.SQLG_PATH_FAKE_LABEL);
          }
        }
        if (previous == null) {
          sqlgGraphStepCompiled=new SqlgGraphStepCompiled(this.sqlgGraph,traversal,originalGraphStep.getReturnClass(),originalGraphStep.getIds());
          sqlgGraphStepCompiled.addReplacedStep(replacedStep);
          TraversalHelper.replaceStep(step,sqlgGraphStepCompiled,traversal);
          collectHasSteps(stepIterator,traversal,replacedStep,pathCount);
        }
 else {
          sqlgGraphStepCompiled.addReplacedStep(replacedStep);
          if (!repeatStepAdded) {
            traversal.removeStep(step);
          }
          collectHasSteps(stepIterator,traversal,replacedStep,pathCount);
        }
        previous=step;
        lastReplacedStep=replacedStep;
      }
 else {
        if (lastReplacedStep != null) {
          sqlgGraphStepCompiled.parseForStrategy();
          if (!sqlgGraphStepCompiled.isForMultipleQueries()) {
            collectOrderGlobalSteps(step,stepIterator,traversal,lastReplacedStep);
          }
        }
        break;
      }
    }
  }
}