Program: 135945
Project: 135945
Buggy source:
public Object execute(ExecutionEvent event) throws ExecutionException {
  if (!setFields()) {
    return null;
  }
  try {
    Location stepLoc=null;
    LevelNode[] steps=pfNode.getSteps();
    ArrayList replace=new ArrayList(15);
    int stepNumber=1;
    for (int i=0; i < steps.length; i++) {
      UniqueString uname=null;
      if (steps[i] instanceof TheoremNode) {
        ProofNode stepPf=((TheoremNode)steps[i]).getProof();
        if ((stepPf != null) && (stepPf instanceof LeafProofNode)) {
          Location leafPfLoc=stepPf.getLocation();
          stepLoc=leafPfLoc;
          IRegion ir=AdapterFactory.locationToRegion(doc,leafPfLoc);
          String leafPfStr=doc.get(ir.getOffset(),ir.getLength());
          if (leafPfStr.indexOf("String_Node_Str") > -1) {
            displayRenumberError("String_Node_Str");
            return null;
          }
        }
        uname=((TheoremNode)steps[i]).getName();
      }
 else       if (steps[i] instanceof DefStepNode) {
        uname=((DefStepNode)steps[i]).getStepNumber();
      }
 else       if (steps[i] instanceof UseOrHideNode) {
        uname=((UseOrHideNode)steps[i]).getStepName();
      }
 else       if (steps[i] instanceof InstanceNode) {
        uname=((InstanceNode)steps[i]).getStepName();
      }
      if (uname != null) {
        String oldName=uname.toString();
        String newName=oldName.substring(0,oldName.indexOf('>') + 1) + stepNumber;
        stepNumber++;
        replace.add(new StringReplacement(oldName,newName));
      }
    }
    StringReplacement[] replaceArray=new StringReplacement[replace.size()];
    for (int i=0; i < replaceArray.length; i++) {
      replaceArray[i]=(StringReplacement)replace.get(i);
    }
    Arrays.sort(replaceArray);
    IRegion pfRegion=AdapterFactory.locationToRegion(doc,pfNode.getLocation());
    int startRegion=pfRegion.getOffset();
    int endRegion=startRegion + pfRegion.getLength();
    ArrayList replacementOffsets=new ArrayList(40);
    for (int i=0; i < replaceArray.length; i++) {
      int searchFrom=startRegion;
      int nextInsert=0;
      boolean done=false;
      String oldString=replaceArray[i].oldStr;
      while (!done) {
        int nextFound=text.indexOf(oldString,searchFrom);
        if ((nextFound == -1) || !(nextFound < endRegion)) {
          done=true;
        }
 else {
          while ((nextInsert < replacementOffsets.size()) && (((IntPair)replacementOffsets.get(nextInsert)).one < nextFound)) {
            nextInsert++;
          }
          if ((nextInsert == replacementOffsets.size()) || (((IntPair)replacementOffsets.get(nextInsert)).one != nextFound)) {
            replacementOffsets.add(nextInsert,new IntPair(nextFound,i));
            nextInsert++;
          }
          searchFrom=nextFound + 1;
        }
      }
    }
    for (int i=replacementOffsets.size() - 1; i > -1; i--) {
      IntPair pair=(IntPair)replacementOffsets.get(i);
      StringReplacement rep=replaceArray[pair.two];
      doc.replace(pair.one,rep.oldStr.length(),rep.newStr);
    }
  }
 catch (  BadLocationException e) {
  }
  resetFields();
  return null;
}

Fixed version (ground truth):
public Object execute(ExecutionEvent event) throws ExecutionException {
  if (!setFields(true)) {
    return null;
  }
  try {
    Location stepLoc=null;
    LevelNode[] steps=pfNode.getSteps();
    ArrayList replace=new ArrayList(15);
    int stepNumber=1;
    for (int i=0; i < steps.length; i++) {
      UniqueString uname=null;
      if (steps[i] instanceof TheoremNode) {
        ProofNode stepPf=((TheoremNode)steps[i]).getProof();
        if ((stepPf != null) && (stepPf instanceof LeafProofNode)) {
          Location leafPfLoc=stepPf.getLocation();
          stepLoc=leafPfLoc;
          IRegion ir=AdapterFactory.locationToRegion(doc,leafPfLoc);
          String leafPfStr=doc.get(ir.getOffset(),ir.getLength());
          if (leafPfStr.indexOf("String_Node_Str") > -1) {
            displayRenumberError("String_Node_Str");
            return null;
          }
        }
        uname=((TheoremNode)steps[i]).getName();
      }
 else       if (steps[i] instanceof DefStepNode) {
        uname=((DefStepNode)steps[i]).getStepNumber();
      }
 else       if (steps[i] instanceof UseOrHideNode) {
        uname=((UseOrHideNode)steps[i]).getStepName();
      }
 else       if (steps[i] instanceof InstanceNode) {
        uname=((InstanceNode)steps[i]).getStepName();
      }
      if (uname != null) {
        String oldName=uname.toString();
        String newName=oldName.substring(0,oldName.indexOf('>') + 1) + stepNumber;
        stepNumber++;
        replace.add(new StringReplacement(oldName,newName));
      }
    }
    StringReplacement[] replaceArray=new StringReplacement[replace.size()];
    for (int i=0; i < replaceArray.length; i++) {
      replaceArray[i]=(StringReplacement)replace.get(i);
    }
    Arrays.sort(replaceArray);
    IRegion pfRegion=AdapterFactory.locationToRegion(doc,pfNode.getLocation());
    int startRegion=pfRegion.getOffset();
    int endRegion=startRegion + pfRegion.getLength();
    ArrayList replacementOffsets=new ArrayList(40);
    for (int i=0; i < replaceArray.length; i++) {
      int searchFrom=startRegion;
      int nextInsert=0;
      boolean done=false;
      String oldString=replaceArray[i].oldStr;
      while (!done) {
        int nextFound=text.indexOf(oldString,searchFrom);
        if ((nextFound == -1) || !(nextFound < endRegion)) {
          done=true;
        }
 else {
          while ((nextInsert < replacementOffsets.size()) && (((IntPair)replacementOffsets.get(nextInsert)).one < nextFound)) {
            nextInsert++;
          }
          if ((nextInsert == replacementOffsets.size()) || (((IntPair)replacementOffsets.get(nextInsert)).one != nextFound)) {
            replacementOffsets.add(nextInsert,new IntPair(nextFound,i));
            nextInsert++;
          }
          searchFrom=nextFound + 1;
        }
      }
    }
    for (int i=replacementOffsets.size() - 1; i > -1; i--) {
      IntPair pair=(IntPair)replacementOffsets.get(i);
      StringReplacement rep=replaceArray[pair.two];
      doc.replace(pair.one,rep.oldStr.length(),rep.newStr);
    }
  }
 catch (  BadLocationException e) {
  }
  resetFields();
  return null;
}