Program: 135992
Project: 135992
Buggy source:
/** 
 * Computes the   {@link TLAProofPosition} for the {@link TheoremNode} and for any subproofs. For each proof in tree representedby theoremNode, this determines if a matching fold exists in previousFolds. If one does exist, it is removed from previous folds. If one does not exist, a new  {@link TLAProofPosition} is created for the proofand is added to additions. Any  {@link TLAProofPosition} that is added to additions or removed from previousFolds is addedto foldsInCurrentTree.
 * @param theoremNode
 * @throws BadLocationException 
 */
private void computeProofFoldPositions(TheoremNode theoremNode,HashMap additions,List foldsInCurrentTree,List previousFolds) throws BadLocationException {
  if (theoremNode.getProof() == null) {
    return;
  }
  IRegion theoremStatementRegion=AdapterFactory.locationToRegion(document,theoremNode.getTheorem().getLocation());
  ProofNode proofNode=theoremNode.getProof();
  IRegion proofNodeRegion=AdapterFactory.locationToRegion(document,proofNode.getLocation());
  if (document.getLineOfOffset(theoremStatementRegion.getOffset() + theoremStatementRegion.getLength()) == document.getLineOfOffset(proofNodeRegion.getOffset() + proofNodeRegion.getLength())) {
    return;
  }
  TLAProofPosition matchingPosition=null;
  for (Iterator it=previousFolds.iterator(); it.hasNext(); ) {
    TLAProofPosition proofPosition=(TLAProofPosition)it.next();
    if (proofPosition.isSamePosition(proofNodeRegion,document)) {
      matchingPosition=proofPosition;
      foldsInCurrentTree.add(matchingPosition);
      it.remove();
      break;
    }
  }
  if (matchingPosition == null) {
    matchingPosition=new TLAProofPosition(proofNodeRegion.getOffset(),proofNodeRegion.getLength(),theoremStatementRegion.getOffset(),theoremStatementRegion.getLength(),new ProjectionAnnotation(),document);
    additions.put(matchingPosition.getAnnotation(),matchingPosition);
    foldsInCurrentTree.add(matchingPosition);
  }
  if (proofNode instanceof NonLeafProofNode) {
    NonLeafProofNode nonLeafProofNode=(NonLeafProofNode)proofNode;
    LevelNode[] steps=nonLeafProofNode.getSteps();
    for (int i=0; i < steps.length; i++) {
      if (steps[i] instanceof TheoremNode) {
        computeProofFoldPositions((TheoremNode)steps[i],additions,foldsInCurrentTree,previousFolds);
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * Computes the   {@link TLAProofPosition} for the {@link TheoremNode} and for any subproofs. For each proof in tree representedby theoremNode, this determines if a matching fold exists in previousFolds. If one does exist, it is removed from previous folds. If one does not exist, a new  {@link TLAProofPosition} is created for the proofand is added to additions. Any  {@link TLAProofPosition} that is added to additions or removed from previousFolds is addedto foldsInCurrentTree.
 * @param theoremNode
 * @throws BadLocationException 
 */
private void computeProofFoldPositions(TheoremNode theoremNode,HashMap additions,List foldsInCurrentTree,List previousFolds) throws BadLocationException {
  if (theoremNode.getProof() == null) {
    return;
  }
  IRegion theoremStatementRegion=AdapterFactory.locationToRegion(document,theoremNode.getTheorem().getLocation());
  IRegion theoremRegion=AdapterFactory.locationToRegion(document,theoremNode.getLocation());
  ProofNode proofNode=theoremNode.getProof();
  IRegion proofNodeRegion=AdapterFactory.locationToRegion(document,proofNode.getLocation());
  if (document.getLineOfOffset(theoremStatementRegion.getOffset() + theoremStatementRegion.getLength()) == document.getLineOfOffset(proofNodeRegion.getOffset() + proofNodeRegion.getLength())) {
    return;
  }
  TLAProofPosition matchingPosition=null;
  for (Iterator it=previousFolds.iterator(); it.hasNext(); ) {
    TLAProofPosition proofPosition=(TLAProofPosition)it.next();
    if (proofPosition.isSamePosition(proofNodeRegion,document)) {
      matchingPosition=proofPosition;
      foldsInCurrentTree.add(matchingPosition);
      it.remove();
      break;
    }
  }
  if (matchingPosition == null) {
    matchingPosition=new TLAProofPosition(proofNodeRegion.getOffset(),proofNodeRegion.getLength(),theoremRegion.getOffset(),theoremStatementRegion.getOffset() + theoremStatementRegion.getLength() - theoremRegion.getOffset(),new ProjectionAnnotation(),document);
    additions.put(matchingPosition.getAnnotation(),matchingPosition);
    foldsInCurrentTree.add(matchingPosition);
  }
  if (proofNode instanceof NonLeafProofNode) {
    NonLeafProofNode nonLeafProofNode=(NonLeafProofNode)proofNode;
    LevelNode[] steps=nonLeafProofNode.getSteps();
    for (int i=0; i < steps.length; i++) {
      if (steps[i] instanceof TheoremNode) {
        computeProofFoldPositions((TheoremNode)steps[i],additions,foldsInCurrentTree,previousFolds);
      }
    }
  }
}