Program: 17445
Project: 17445
Buggy source:
/** 
 * Called when the document content changes. Updates partitions based on the area of text that has changed.
 */
public IRegion documentChanged2(DocumentEvent e){
  try {
    IDocument d=e.getDocument();
    Position[] category=d.getPositions(fPositionCategory);
    IRegion line=d.getLineInformationOfOffset(e.getOffset());
    int reparseStart=line.getOffset();
    int partitionStart=-1;
    int partitionEnd=partitionStart;
    String contentType=null;
    int newLength=e.getText() == null ? 0 : e.getText().length();
    int first=d.computeIndexInCategory(fPositionCategory,reparseStart);
    Position[] pos=d.getPositions(fPositionCategory);
    System.out.println("String_Node_Str" + e.fOffset + "String_Node_Str"+ e.fLength+ "String_Node_Str"+ e.fText);
    if (first > 0) {
      CFEPartition partition=(CFEPartition)category[first - 1];
      partitionStart=partition.getOffset();
      partitionEnd=partition.getOffset() + partition.getLength();
      contentType=partition.getType();
      System.out.println("String_Node_Str" + contentType + "String_Node_Str"+ partition.offset);
      Object[] partitions=fPseudoPartitions.values().toArray();
      for (int i=0; i < partitions.length; i++) {
        if (partitions[i].toString().equals(contentType)) {
          --first;
          partition=(CFEPartition)category[first - 1];
          partitionEnd=partition.getOffset() + partition.getLength();
          partitionStart=partitionEnd + 1;
          contentType=partition.getType();
          reparseStart=partitionEnd;
          break;
        }
      }
      if (partition.getNextPartitionType() != IDocument.DEFAULT_CONTENT_TYPE) {
        fPseudoPartition=partition.getNextPartitionType();
        fPseudoPartitionStart=partition.getOffset() + partition.getLength();
      }
      if (partition.includes(reparseStart)) {
        if (e.getOffset() == partitionEnd) {
          reparseStart=partitionStart;
        }
        --first;
      }
 else       if (reparseStart == e.getOffset() && reparseStart == partitionEnd) {
        reparseStart=partitionStart;
        --first;
      }
 else {
        if (fPseudoPartition == null) {
          partitionStart=partition.getOffset() + partition.getLength();
        }
        contentType=IDocument.DEFAULT_CONTENT_TYPE;
      }
      if (contentType.equals(CFPartitionScanner.CF_COMMENT) || contentType.equals(CFPartitionScanner.HTM_COMMENT)) {
        reparseStart=partitionStart;
      }
    }
    fPositionUpdater.update(e);
    for (int i=first; i < category.length; i++) {
      Position p=category[i];
      CFEPartition cfp=(CFEPartition)p;
      if (p.isDeleted) {
        rememberDeletedOffset(e.getOffset());
        break;
      }
    }
    category=d.getPositions(fPositionCategory);
    fScanner.setPartialRange(d,reparseStart,d.getLength() - reparseStart,contentType,partitionStart);
    int lastScannedPosition=reparseStart;
    IToken token=fScanner.nextToken();
    int lastOffset=-1;
    while (!token.isEOF()) {
      lastOffset=fScanner.getTokenOffset();
      contentType=getTokenContentType(token);
      System.out.println("String_Node_Str" + contentType + "String_Node_Str"+ fScanner.getTokenOffset()+ "String_Node_Str"+ fScanner.getTokenLength());
      if (!isSupportedContentType(contentType)) {
        token=fScanner.nextToken();
        continue;
      }
      int start=fScanner.getTokenOffset();
      int length=fScanner.getTokenLength();
      lastScannedPosition=start + length - 1;
      while (first < category.length) {
        CFEPartition p=(CFEPartition)category[first];
        if (lastScannedPosition >= p.offset + p.length || (p.overlapsWith(start,length) && (!d.containsPosition(fPositionCategory,start,length) || !contentType.equals(p.getType())))) {
          rememberRegion(p.offset,p.length);
          d.removePosition(fPositionCategory,p);
          ++first;
        }
 else         break;
      }
      if (d.containsPosition(fPositionCategory,start,length)) {
        if (lastScannedPosition >= e.getOffset() + newLength) {
          if (fPseudoPartition != null) {
            handleToken(token,getTokenContentType(token));
          }
          return createRegion();
        }
        ++first;
      }
 else {
        handleToken(token,getTokenContentType(token));
        rememberRegion(start,length);
      }
      token=fScanner.nextToken();
    }
    if (lastScannedPosition != reparseStart) {
      ++lastScannedPosition;
    }
    first=d.computeIndexInCategory(fPositionCategory,lastScannedPosition);
    CFEPartition p;
    while (first < category.length) {
      p=(CFEPartition)category[first++];
      d.removePosition(fPositionCategory,p);
      rememberRegion(p.offset,p.length);
    }
  }
 catch (  BadPositionCategoryException x) {
  }
catch (  BadLocationException x) {
  }
catch (  Exception ex) {
    ex.printStackTrace();
  }
  return createRegion();
}

Fixed version (ground truth):
/** 
 * Called when the document content changes. Updates partitions based on the area of text that has changed.
 */
public IRegion documentChanged2(DocumentEvent e){
  try {
    IDocument d=e.getDocument();
    Position[] category=d.getPositions(fPositionCategory);
    IRegion line=d.getLineInformationOfOffset(e.getOffset());
    int reparseStart=line.getOffset();
    int partitionStart=-1;
    int partitionEnd=partitionStart;
    String contentType=null;
    int newLength=e.getText() == null ? 0 : e.getText().length();
    int first=d.computeIndexInCategory(fPositionCategory,reparseStart);
    Position[] pos=d.getPositions(fPositionCategory);
    if (first > 0) {
      CFEPartition partition=(CFEPartition)category[first - 1];
      partitionStart=partition.getOffset();
      partitionEnd=partition.getOffset() + partition.getLength();
      contentType=partition.getType();
      Object[] partitions=fPseudoPartitions.values().toArray();
      for (int i=0; i < partitions.length; i++) {
        if (partitions[i].toString().equals(contentType)) {
          --first;
          partition=(CFEPartition)category[first - 1];
          partitionEnd=partition.getOffset() + partition.getLength();
          partitionStart=partitionEnd + 1;
          contentType=partition.getType();
          reparseStart=partitionEnd;
          break;
        }
      }
      if (partition.getNextPartitionType() != IDocument.DEFAULT_CONTENT_TYPE) {
        fPseudoPartition=partition.getNextPartitionType();
        fPseudoPartitionStart=partition.getOffset() + partition.getLength();
      }
      if (partition.includes(reparseStart)) {
        if (e.getOffset() == partitionEnd) {
          reparseStart=partitionStart;
        }
        --first;
      }
 else       if (reparseStart == e.getOffset() && reparseStart == partitionEnd) {
        reparseStart=partitionStart;
        --first;
      }
 else {
        if (fPseudoPartition == null) {
          partitionStart=partition.getOffset() + partition.getLength();
        }
        contentType=IDocument.DEFAULT_CONTENT_TYPE;
      }
      if (contentType.equals(CFPartitionScanner.CF_COMMENT) || contentType.equals(CFPartitionScanner.HTM_COMMENT)) {
        reparseStart=partitionStart;
      }
    }
    fPositionUpdater.update(e);
    for (int i=first; i < category.length; i++) {
      Position p=category[i];
      CFEPartition cfp=(CFEPartition)p;
      if (p.isDeleted) {
        rememberDeletedOffset(e.getOffset());
        break;
      }
    }
    category=d.getPositions(fPositionCategory);
    fScanner.setPartialRange(d,reparseStart,d.getLength() - reparseStart,contentType,partitionStart);
    int lastScannedPosition=reparseStart;
    IToken token=fScanner.nextToken();
    int lastOffset=-1;
    while (!token.isEOF()) {
      lastOffset=fScanner.getTokenOffset();
      contentType=getTokenContentType(token);
      if (contentType != null) {
      }
      if (!isSupportedContentType(contentType)) {
        token=fScanner.nextToken();
        continue;
      }
      int start=fScanner.getTokenOffset();
      int length=fScanner.getTokenLength();
      lastScannedPosition=start + length - 1;
      while (first < category.length) {
        CFEPartition p=(CFEPartition)category[first];
        if (lastScannedPosition >= p.offset + p.length || (p.overlapsWith(start,length) && (!d.containsPosition(fPositionCategory,start,length) || !contentType.equals(p.getType())))) {
          rememberRegion(p.offset,p.length);
          d.removePosition(fPositionCategory,p);
          ++first;
        }
 else         break;
      }
      if (d.containsPosition(fPositionCategory,start,length)) {
        if (fPseudoPartition != null) {
          handleToken(token,getTokenContentType(token));
        }
        if (lastScannedPosition >= e.getOffset() + newLength) {
          return createRegion();
        }
        ++first;
      }
 else {
        handleToken(token,getTokenContentType(token));
        rememberRegion(start,length);
      }
      token=fScanner.nextToken();
    }
    if (lastScannedPosition != reparseStart) {
      ++lastScannedPosition;
    }
    first=d.computeIndexInCategory(fPositionCategory,lastScannedPosition);
    CFEPartition p;
    while (first < category.length) {
      p=(CFEPartition)category[first++];
      d.removePosition(fPositionCategory,p);
      rememberRegion(p.offset,p.length);
    }
  }
 catch (  BadPositionCategoryException x) {
  }
catch (  BadLocationException x) {
  }
catch (  Exception ex) {
    ex.printStackTrace();
  }
  return createRegion();
}