Program: 17451
Project: 17451
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;
    String nextPartitionType=null;
    int newLength=e.getText() == null ? 0 : e.getText().length();
    int reparseEnd=e.getOffset() + newLength;
    int first=d.computeIndexInCategory(fPositionCategory,e.getOffset());
    CFEPartition activePartition=null;
    if (first > 0) {
      activePartition=(CFEPartition)category[first - 1];
      String partitionType=activePartition.getType();
      if (partitionType.endsWith("String_Node_Str")) {
        --first;
        d.removePosition(fPositionCategory,activePartition);
        activePartition=(CFEPartition)category[first - 1];
        if (!activePartition.getType().endsWith("String_Node_Str")) {
          --first;
          d.removePosition(fPositionCategory,activePartition);
          activePartition=(CFEPartition)category[first - 1];
        }
      }
 else {
        if (partitionType.equals(CFPartitionScanner.CF_BOOLEAN_STATEMENT) || partitionType.equals(CFPartitionScanner.CF_EXPRESSION) || partitionType.equals(CFPartitionScanner.CF_SET_STATEMENT)|| partitionType.endsWith("String_Node_Str")) {
          --first;
          d.removePosition(fPositionCategory,activePartition);
          activePartition=(CFEPartition)category[first - 1];
        }
      }
      if (first - 2 > 0) {
        CFEPartition prevPartition=(CFEPartition)category[first - 2];
        nextPartitionType=prevPartition.getNextPartitionType();
      }
      if (isPseudoPartition(activePartition.getType())) {
        String pseudoPartitionType=activePartition.getType();
        while (first > 0) {
          --first;
          activePartition=(CFEPartition)category[first];
          if (pseudoPartitionType.equals(activePartition.getOpensPartitionType())) {
            reparseStart=activePartition.getOffset() + activePartition.getLength();
            break;
          }
        }
      }
      if (activePartition.offset + activePartition.length < e.fOffset) {
        partitionType=IDocument.DEFAULT_CONTENT_TYPE;
      }
      if (activePartition.getType().endsWith("String_Node_Str") || activePartition.getType().endsWith("String_Node_Str")) {
        int index=first;
        reparseEnd=d.getLength();
        d.removePosition(fPositionCategory,activePartition);
        while (index < category.length) {
          CFEPartition endPartition=(CFEPartition)category[index];
          if (endPartition.getType().endsWith("String_Node_Str") || endPartition.getType().endsWith("String_Node_Str")) {
            reparseEnd=endPartition.getOffset() + endPartition.getLength();
            break;
          }
          index++;
        }
      }
      contentType=IDocument.DEFAULT_CONTENT_TYPE;
      partitionStart=activePartition.getOffset();
      partitionEnd=activePartition.getOffset() + activePartition.getLength();
      if (partitionType.equals(CFPartitionScanner.CF_COMMENT) || partitionType.equals(CFPartitionScanner.HTM_COMMENT)) {
        System.out.println("String_Node_Str" + partitionStart + "String_Node_Str"+ partitionType);
        reparseStart=partitionStart;
        contentType=CFPartitionScanner.CF_COMMENT;
      }
    }
 else     if (category != null && category.length > 0) {
      activePartition=(CFEPartition)category[first];
    }
    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 (!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())))) {
          String closes=p.getClosesPartitionType();
          String opens=p.getOpensPartitionType();
          if (closes != null) {
          }
          if (opens != null) {
          }
          if (!p.getType().equals(p.getNextPartitionType())) {
            rememberRegion(p.offset,p.length);
            d.removePosition(fPositionCategory,p);
          }
 else {
            if (p.offset + p.length > start) {
              int oldLength=p.length;
              p.length=start - p.offset;
            }
 else             if (p.offset + p.length < start) {
              p.length=start - p.offset;
            }
 else {
            }
            if (p.length < 0) {
              rememberRegion(p.offset,p.length);
              d.removePosition(fPositionCategory,p);
            }
          }
          ++first;
        }
 else         break;
      }
      if (d.containsPosition(fPositionCategory,start,length)) {
        if (lastScannedPosition >= reparseEnd) {
          return createRegion();
        }
        ++first;
      }
 else {
        handleToken(token,getTokenContentType(token),nextPartitionType);
        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=IDocument.DEFAULT_CONTENT_TYPE;
    ;
    String nextPartitionType=null;
    int newLength=e.getText() == null ? 0 : e.getText().length();
    int reparseEnd=e.getOffset() + newLength;
    int first=d.computeIndexInCategory(fPositionCategory,e.getOffset());
    CFEPartition activePartition=null;
    if (first > 0) {
      activePartition=(CFEPartition)category[first - 1];
      String partitionType=activePartition.getType();
      if (partitionType.endsWith("String_Node_Str")) {
        --first;
        d.removePosition(fPositionCategory,activePartition);
        activePartition=(CFEPartition)category[first - 1];
        if (!activePartition.getType().endsWith("String_Node_Str")) {
          --first;
          d.removePosition(fPositionCategory,activePartition);
          activePartition=(CFEPartition)category[first - 1];
        }
      }
 else {
        if (partitionType.equals(CFPartitionScanner.CF_BOOLEAN_STATEMENT) || partitionType.equals(CFPartitionScanner.CF_EXPRESSION) || partitionType.equals(CFPartitionScanner.CF_SET_STATEMENT)|| partitionType.endsWith("String_Node_Str")) {
          d.removePosition(fPositionCategory,activePartition);
          activePartition=(CFEPartition)category[first - 1];
        }
      }
      if (first - 2 > 0) {
        CFEPartition prevPartition=(CFEPartition)category[first - 2];
        nextPartitionType=prevPartition.getNextPartitionType();
      }
      if (isPseudoPartition(activePartition.getType())) {
        String pseudoPartitionType=activePartition.getType();
        while (first > 0) {
          --first;
          activePartition=(CFEPartition)category[first];
          if (pseudoPartitionType.equals(activePartition.getOpensPartitionType())) {
            reparseStart=activePartition.getOffset() + activePartition.getLength();
            break;
          }
        }
      }
      if (activePartition.offset + activePartition.length < e.fOffset) {
        partitionType=IDocument.DEFAULT_CONTENT_TYPE;
      }
      if (activePartition.getType().endsWith("String_Node_Str") || activePartition.getType().endsWith("String_Node_Str")) {
        int index=first;
        reparseEnd=d.getLength();
        d.removePosition(fPositionCategory,activePartition);
        while (index < category.length) {
          CFEPartition endPartition=(CFEPartition)category[index];
          if (endPartition.getType().endsWith("String_Node_Str") || endPartition.getType().endsWith("String_Node_Str")) {
            reparseEnd=endPartition.getOffset() + endPartition.getLength();
            break;
          }
          index++;
        }
      }
      partitionStart=activePartition.getOffset();
      partitionEnd=activePartition.getOffset() + activePartition.getLength();
      if (partitionType.equals(CFPartitionScanner.CF_COMMENT) || partitionType.equals(CFPartitionScanner.HTM_COMMENT)) {
        reparseStart=partitionStart;
        contentType=CFPartitionScanner.CF_COMMENT;
      }
    }
 else     if (category != null && category.length > 0) {
      activePartition=(CFEPartition)category[first];
    }
    fPositionUpdater.update(e);
    if (category.length > first) {
      for (int i=first; i > 0; i--) {
        Position p=category[i];
        if (p.offset + p.length > reparseStart) {
          d.removePosition(fPositionCategory,p);
        }
 else {
          break;
        }
      }
    }
    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 (!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())))) {
          String closes=p.getClosesPartitionType();
          String opens=p.getOpensPartitionType();
          if (closes != null) {
          }
          if (opens != null) {
          }
          if (!p.getType().equals(p.getNextPartitionType())) {
            rememberRegion(p.offset,p.length);
            d.removePosition(fPositionCategory,p);
          }
 else {
            if (p.offset + p.length > start) {
              int oldLength=p.length;
              p.length=start - p.offset;
            }
 else             if (p.offset + p.length < start) {
              p.length=start - p.offset;
            }
 else {
            }
            if (p.length < 0) {
              rememberRegion(p.offset,p.length);
              d.removePosition(fPositionCategory,p);
            }
          }
          ++first;
        }
 else         break;
      }
      if (d.containsPosition(fPositionCategory,start,length)) {
        if (lastScannedPosition >= reparseEnd) {
          return createRegion();
        }
        ++first;
      }
 else {
        handleToken(token,getTokenContentType(token),nextPartitionType);
        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();
}