Program: 135978
Project: 135978
Buggy source:
/** 
 * Called when there is a new parse result broadcast by  {@link ParseResultBroadcaster}. Updates the folding structure of the proofs in the editor.
 */
public void newParseResult(ParseResult parseResult){
  String moduleName=ResourceHelper.getModuleName(((FileEditorInput)editor.getEditorInput()).getFile());
  if (editor == null) {
    Activator.logDebug("String_Node_Str");
    return;
  }
 else   if (editor.getEditorInput() == null) {
    Activator.logDebug("String_Node_Str");
    return;
  }
  if (editor.isDirty() || parseResult.getParserCalled() < documentLastModified || parseResult.getParserCalled() < ((FileEditorInput)editor.getEditorInput()).getFile().getLocalTimeStamp()) {
    return;
  }
  SpecObj specObj=parseResult.getSpecObj();
  if (specObj == null) {
    return;
  }
  Assert.isNotNull(specObj.getExternalModuleTable());
  ModuleNode moduleNode=specObj.getExternalModuleTable().getModuleNode(UniqueString.uniqueStringOf(moduleName));
  if (moduleNode == null) {
    return;
  }
  canPerformFoldingCommands=false;
  HashMap additions=new HashMap();
  Vector foldsInCurrentTree=new Vector();
  TheoremNode[] theorems=moduleNode.getTheorems();
  for (int i=0; i < theorems.length; i++) {
    TheoremNode theoremNode=theorems[i];
    try {
      if (theoremNode.getLocation().source().equals(moduleName)) {
        computeProofFoldPositions(theoremNode,additions,foldsInCurrentTree,foldPositions);
      }
    }
 catch (    BadLocationException e) {
      Activator.logError("String_Node_Str" + moduleName,e);
    }
  }
  Annotation[] deletions=new ProjectionAnnotation[foldPositions.size()];
  int i=0;
  for (Iterator it=foldPositions.iterator(); it.hasNext(); ) {
    TLAProofPosition proofPosition=(TLAProofPosition)it.next();
    proofPosition.remove(document);
    deletions[i]=proofPosition.getAnnotation();
  }
  foldPositions=foldsInCurrentTree;
  editor.modifyProjectionAnnotations(deletions,additions,null);
  int currentOffset=-1;
  boolean isSorted=true;
  for (Iterator it=foldPositions.iterator(); it.hasNext(); ) {
    TLAProofPosition proofPosition=(TLAProofPosition)it.next();
    if (proofPosition.getOffset() >= currentOffset) {
      currentOffset=proofPosition.getOffset();
    }
 else {
      isSorted=false;
      break;
    }
  }
  if (!isSorted) {
    Collections.sort(foldPositions,new Comparator(){
      public int compare(      Object arg0,      Object arg1){
        if (arg0 instanceof TLAProofPosition && arg1 instanceof TLAProofPosition) {
          return ((TLAProofPosition)arg0).getOffset() - ((TLAProofPosition)arg1).getOffset();
        }
 else {
          return 0;
        }
      }
    }
);
  }
  canPerformFoldingCommands=true;
}

Fixed version (ground truth):
/** 
 * Called when there is a new parse result broadcast by  {@link ParseResultBroadcaster}. Updates the folding structure of the proofs in the editor if the parse result points to the   {@link ModuleNode} representingthe file in the editor for this class.
 */
public void newParseResult(ParseResult parseResult){
  if (!parseResult.getParsedResource().getLocation().removeLastSegments(1).equals(((FileEditorInput)editor.getEditorInput()).getFile().getLocation().removeLastSegments(1))) {
    return;
  }
  String moduleName=ResourceHelper.getModuleName(((FileEditorInput)editor.getEditorInput()).getFile());
  if (editor == null) {
    Activator.logDebug("String_Node_Str");
    return;
  }
 else   if (editor.getEditorInput() == null) {
    Activator.logDebug("String_Node_Str");
    return;
  }
  if (editor.isDirty() || parseResult.getParserCalled() < documentLastModified || parseResult.getParserCalled() < ((FileEditorInput)editor.getEditorInput()).getFile().getLocalTimeStamp()) {
    return;
  }
  SpecObj specObj=parseResult.getSpecObj();
  if (specObj == null) {
    return;
  }
  Assert.isNotNull(specObj.getExternalModuleTable());
  ModuleNode moduleNode=specObj.getExternalModuleTable().getModuleNode(UniqueString.uniqueStringOf(moduleName));
  if (moduleNode == null) {
    return;
  }
  canPerformFoldingCommands=false;
  HashMap additions=new HashMap();
  Vector foldsInCurrentTree=new Vector();
  TheoremNode[] theorems=moduleNode.getTheorems();
  for (int i=0; i < theorems.length; i++) {
    TheoremNode theoremNode=theorems[i];
    try {
      if (theoremNode.getLocation().source().equals(moduleName)) {
        computeProofFoldPositions(theoremNode,additions,foldsInCurrentTree,foldPositions);
      }
    }
 catch (    BadLocationException e) {
      Activator.logError("String_Node_Str" + moduleName,e);
    }
  }
  Annotation[] deletions=new ProjectionAnnotation[foldPositions.size()];
  int i=0;
  for (Iterator it=foldPositions.iterator(); it.hasNext(); ) {
    TLAProofPosition proofPosition=(TLAProofPosition)it.next();
    proofPosition.remove(document);
    deletions[i]=proofPosition.getAnnotation();
  }
  foldPositions=foldsInCurrentTree;
  editor.modifyProjectionAnnotations(deletions,additions,null);
  int currentOffset=-1;
  boolean isSorted=true;
  for (Iterator it=foldPositions.iterator(); it.hasNext(); ) {
    TLAProofPosition proofPosition=(TLAProofPosition)it.next();
    if (proofPosition.getOffset() >= currentOffset) {
      currentOffset=proofPosition.getOffset();
    }
 else {
      isSorted=false;
      break;
    }
  }
  if (!isSorted) {
    Collections.sort(foldPositions,new Comparator(){
      public int compare(      Object arg0,      Object arg1){
        if (arg0 instanceof TLAProofPosition && arg1 instanceof TLAProofPosition) {
          return ((TLAProofPosition)arg0).getOffset() - ((TLAProofPosition)arg1).getOffset();
        }
 else {
          return 0;
        }
      }
    }
);
  }
  canPerformFoldingCommands=true;
}