Program: 135888
Project: 135888
Buggy source:
/** 
 * {@inheritDoc}<p> May be extended by subclasses. </p>
 */
public IRegion documentChanged2(DocumentEvent e){
  if (!fIsInitialized)   return null;
  try {
    Assert.isTrue(e.getDocument() == fDocument);
    Position[] category=getPositions();
    IRegion line=fDocument.getLineInformationOfOffset(e.getOffset());
    int reparseStart=line.getOffset();
    if ((pcalStartOffset != -1) && (reparseStart < pcalStartOffset + pcalStartLength) && (pcalStartCommentOffset < reparseStart)) {
      reparseStart=pcalStartCommentOffset;
    }
 else     if ((pcalEndCommentOffset != -1) && (reparseStart < pcalEndCommentOffset + pcalEndCommentLength) && (pcalEndCommentOffset < reparseStart)) {
      reparseStart=pcalEndCommentOffset;
    }
    int newLength=e.getText() == null ? 0 : e.getText().length();
    int partitionStart=-1;
    String contentType=null;
    int first=fDocument.computeIndexInCategory(fPositionCategory,reparseStart);
    if (first > 0) {
      TypedPosition partition=(TypedPosition)category[first - 1];
      if (partition.includes(reparseStart)) {
        partitionStart=partition.getOffset();
        contentType=partition.getType();
        if (e.getOffset() == partition.getOffset() + partition.getLength())         reparseStart=partitionStart;
        --first;
      }
 else       if (reparseStart == e.getOffset() && reparseStart == partition.getOffset() + partition.getLength()) {
        partitionStart=partition.getOffset();
        contentType=partition.getType();
        reparseStart=partitionStart;
        --first;
      }
 else {
        partitionStart=partition.getOffset() + partition.getLength();
        contentType=IDocument.DEFAULT_CONTENT_TYPE;
      }
    }
    int pcalMode=BEFORE_PCAL;
    if (((pcalStartOffset != -1) && (pcalStartOffset <= reparseStart)) && ((pcalEndCommentOffset == -1) || (reparseStart < pcalEndCommentOffset + pcalEndCommentLength))) {
      pcalMode=IN_PCAL;
    }
 else     if ((pcalEndCommentOffset != -1) && (pcalEndCommentOffset + pcalEndCommentLength <= reparseStart)) {
      pcalMode=AFTER_PCAL;
    }
    fPositionUpdater.update(e);
    for (int i=first; i < category.length; i++) {
      Position p=category[i];
      if (p.isDeleted) {
        rememberDeletedOffset(e.getOffset());
        break;
      }
    }
    clearPositionCache();
    category=getPositions();
    fScanner.setPartialRange(fDocument,reparseStart,fDocument.getLength() - reparseStart,contentType,partitionStart,pcalMode);
    int behindLastScannedPosition=reparseStart;
    IToken token=fScanner.nextToken();
    int Delta=newLength - e.getLength();
    boolean prevPcal=(pcalStartCommentOffset != -1);
    int prevAfterPcal=0;
    if (prevPcal) {
      if (pcalEndCommentOffset == -1) {
        prevAfterPcal=Integer.MAX_VALUE;
      }
 else {
        int tmp=pcalEndCommentOffset + pcalEndCommentLength;
        if (e.getOffset() <= tmp) {
          prevAfterPcal=tmp + Delta;
        }
 else {
          prevAfterPcal=tmp;
        }
      }
    }
    pcalStartCommentOffset=convertOffset(pcalStartCommentOffset,pcalStartOffset - pcalStartCommentOffset,e.getOffset(),e.getLength(),newLength);
    pcalStartOffset=convertOffset(pcalStartOffset,pcalStartLength,e.getOffset(),e.getLength(),newLength);
    pcalEndCommentOffset=convertOffset(pcalEndCommentOffset,pcalEndCommentLength,e.getOffset(),e.getLength(),newLength);
    int state;
    boolean canStop;
    if (pcalMode == BEFORE_PCAL) {
      canStop=(!prevPcal) || ((pcalStartCommentOffset != -1) && (pcalStartOffset != -1)) || (reparseStart >= prevAfterPcal);
      state=SEEK_ALGORITHM;
    }
 else     if (pcalMode == AFTER_PCAL) {
      canStop=true;
      state=AFTER_ALGORITHM;
    }
 else {
      canStop=(pcalEndCommentOffset != -1);
      state=IN_ALGORITHM;
    }
    while (!token.isEOF()) {
      contentType=getTokenContentType(token);
      if (!isSupportedContentType(contentType)) {
        if ((state == IN_ALGORITHM) || (state == START_ALGORITHM)) {
          contentType=TLAPartitionScanner.TLA_PCAL;
        }
 else {
          token=fScanner.nextToken();
          continue;
        }
      }
      int start=fScanner.getTokenOffset();
      int length=fScanner.getTokenLength();
      behindLastScannedPosition=start + length;
      int lastScannedPosition=behindLastScannedPosition - 1;
switch (state) {
case SEEK_ALGORITHM:
        if (contentType.equals(TLAPartitionScanner.TLA_START_PCAL_COMMENT)) {
          pcalStartCommentOffset=start;
          pcalStartOffset=behindLastScannedPosition;
          contentType=TLAPartitionScanner.TLA_MULTI_LINE_COMMENT;
          state=START_ALGORITHM;
        }
 else         if (contentType.equals(TLAPartitionScanner.TLA_END_PCAL_COMMENT)) {
          System.out.println("String_Node_Str");
        }
 else {
          canStop=canStop || (behindLastScannedPosition >= prevAfterPcal);
        }
      break;
case START_ALGORITHM:
    pcalStartLength=length;
  canStop=(pcalEndCommentOffset != -1);
state=IN_ALGORITHM;
if (pcalStartOffset != start) {
System.out.println("String_Node_Str");
}
if (!contentType.equals(TLAPartitionScanner.TLA_PCAL)) {
System.out.println("String_Node_Str");
}
break;
case IN_ALGORITHM:
if (contentType.equals(TLAPartitionScanner.TLA_END_PCAL_COMMENT)) {
canStop=(behindLastScannedPosition >= prevAfterPcal);
pcalEndCommentOffset=start;
pcalEndCommentLength=length;
contentType=TLAPartitionScanner.TLA_MULTI_LINE_COMMENT;
state=AFTER_ALGORITHM;
}
 else if (contentType.equals(TLAPartitionScanner.TLA_START_PCAL_COMMENT)) {
System.out.println("String_Node_Str");
}
break;
case AFTER_ALGORITHM:
if (contentType.equals(TLAPartitionScanner.TLA_START_PCAL_COMMENT) || contentType.equals(TLAPartitionScanner.TLA_END_PCAL_COMMENT)) {
System.out.println("String_Node_Str");
}
canStop=canStop || (behindLastScannedPosition >= prevAfterPcal);
break;
default :
System.out.println("String_Node_Str");
}
while (first < category.length) {
TypedPosition p=(TypedPosition)category[first];
if (lastScannedPosition >= p.offset + p.length || (p.overlapsWith(start,length) && (!fDocument.containsPosition(fPositionCategory,start,length) || !contentType.equals(p.getType())))) {
rememberRegion(p.offset,p.length);
fDocument.removePosition(fPositionCategory,p);
++first;
}
 else break;
}
if (fDocument.containsPosition(fPositionCategory,start,length)) {
if ((lastScannedPosition >= e.getOffset() + newLength) && canStop) {
return createRegion();
}
++first;
}
 else {
try {
fDocument.addPosition(fPositionCategory,new TypedPosition(start,length,contentType));
rememberRegion(start,length);
}
 catch (BadPositionCategoryException x) {
}
catch (BadLocationException x) {
}
}
token=fScanner.nextToken();
}
switch (state) {
case SEEK_ALGORITHM:
pcalStartCommentOffset=-1;
pcalStartOffset=-1;
pcalEndCommentOffset=-1;
break;
case START_ALGORITHM:
System.out.println("String_Node_Str");
break;
case IN_ALGORITHM:
pcalEndCommentOffset=-1;
break;
}
first=fDocument.computeIndexInCategory(fPositionCategory,behindLastScannedPosition);
clearPositionCache();
category=getPositions();
TypedPosition p;
while (first < category.length) {
p=(TypedPosition)category[first++];
fDocument.removePosition(fPositionCategory,p);
rememberRegion(p.offset,p.length);
}
}
 catch (BadPositionCategoryException x) {
}
catch (BadLocationException x) {
}
 finally {
clearPositionCache();
}
return createRegion();
}

Fixed version (ground truth):
/** 
 * {@inheritDoc}<p> May be extended by subclasses. </p>
 */
public IRegion documentChanged2(DocumentEvent e){
  if (!fIsInitialized)   return null;
  try {
    Assert.isTrue(e.getDocument() == fDocument);
    Position[] category=getPositions();
    IRegion line=fDocument.getLineInformationOfOffset(e.getOffset());
    int reparseStart=line.getOffset();
    if ((pcalStartOffset != -1) && (reparseStart < pcalStartOffset + pcalStartLength) && (pcalStartCommentOffset < reparseStart)) {
      reparseStart=pcalStartCommentOffset;
    }
 else     if ((pcalEndCommentOffset != -1) && (reparseStart < pcalEndCommentOffset + pcalEndCommentLength) && (pcalEndCommentOffset < reparseStart)) {
      reparseStart=pcalEndCommentOffset;
    }
    int newLength=e.getText() == null ? 0 : e.getText().length();
    int partitionStart=-1;
    String contentType=null;
    int first=fDocument.computeIndexInCategory(fPositionCategory,reparseStart);
    if (first > 0) {
      TypedPosition partition=(TypedPosition)category[first - 1];
      if (partition.includes(reparseStart)) {
        partitionStart=partition.getOffset();
        contentType=partition.getType();
        if (e.getOffset() == partition.getOffset() + partition.getLength())         reparseStart=partitionStart;
        --first;
      }
 else       if (reparseStart == e.getOffset() && reparseStart == partition.getOffset() + partition.getLength()) {
        partitionStart=partition.getOffset();
        contentType=partition.getType();
        reparseStart=partitionStart;
        --first;
      }
 else {
        partitionStart=partition.getOffset() + partition.getLength();
        contentType=IDocument.DEFAULT_CONTENT_TYPE;
      }
    }
    int pcalMode=BEFORE_PCAL;
    if (((pcalStartOffset != -1) && (pcalStartOffset <= reparseStart)) && ((pcalEndCommentOffset == -1) || (reparseStart < pcalEndCommentOffset + pcalEndCommentLength))) {
      pcalMode=IN_PCAL;
    }
 else     if ((pcalEndCommentOffset != -1) && (pcalEndCommentOffset + pcalEndCommentLength <= reparseStart)) {
      pcalMode=AFTER_PCAL;
    }
    fPositionUpdater.update(e);
    for (int i=first; i < category.length; i++) {
      Position p=category[i];
      if (p.isDeleted) {
        rememberDeletedOffset(e.getOffset());
        break;
      }
    }
    clearPositionCache();
    category=getPositions();
    fScanner.setPartialRange(fDocument,reparseStart,fDocument.getLength() - reparseStart,contentType,partitionStart,pcalMode);
    int behindLastScannedPosition=reparseStart;
    IToken token=fScanner.nextToken();
    int Delta=newLength - e.getLength();
    boolean prevPcal=(pcalStartCommentOffset != -1);
    int prevAfterPcal=0;
    if (prevPcal) {
      if (pcalEndCommentOffset == -1) {
        prevAfterPcal=Integer.MAX_VALUE;
      }
 else {
        int tmp=pcalEndCommentOffset + pcalEndCommentLength;
        if (e.getOffset() <= tmp) {
          prevAfterPcal=tmp + Delta;
        }
 else {
          prevAfterPcal=tmp;
        }
      }
    }
    pcalStartCommentOffset=convertOffset(pcalStartCommentOffset,pcalStartOffset - pcalStartCommentOffset,e.getOffset(),e.getLength(),newLength);
    pcalStartOffset=convertOffset(pcalStartOffset,pcalStartLength,e.getOffset(),e.getLength(),newLength);
    pcalEndCommentOffset=convertOffset(pcalEndCommentOffset,pcalEndCommentLength,e.getOffset(),e.getLength(),newLength);
    int state;
    boolean canStop;
    if (pcalMode == BEFORE_PCAL) {
      canStop=(!prevPcal) || ((pcalStartCommentOffset != -1) && (pcalStartOffset != -1)) || (reparseStart >= prevAfterPcal);
      state=SEEK_ALGORITHM;
    }
 else     if (pcalMode == AFTER_PCAL) {
      canStop=true;
      state=AFTER_ALGORITHM;
    }
 else {
      canStop=(pcalEndCommentOffset != -1);
      state=IN_ALGORITHM;
    }
    while (!token.isEOF()) {
      contentType=getTokenContentType(token);
      if (!isSupportedContentType(contentType)) {
        if ((state == IN_ALGORITHM) || (state == START_ALGORITHM)) {
          contentType=TLAPartitionScanner.TLA_PCAL;
        }
 else {
          token=fScanner.nextToken();
          continue;
        }
      }
      int start=fScanner.getTokenOffset();
      int length=fScanner.getTokenLength();
      behindLastScannedPosition=start + length;
      int lastScannedPosition=behindLastScannedPosition - 1;
switch (state) {
case SEEK_ALGORITHM:
        if (contentType.equals(TLAPartitionScanner.TLA_START_PCAL_COMMENT)) {
          pcalStartCommentOffset=start;
          pcalStartOffset=behindLastScannedPosition;
          contentType=TLAPartitionScanner.TLA_MULTI_LINE_COMMENT;
          state=START_ALGORITHM;
        }
 else         if (contentType.equals(TLAPartitionScanner.TLA_END_PCAL_COMMENT)) {
          System.out.println("String_Node_Str");
        }
 else {
          canStop=canStop || (behindLastScannedPosition >= prevAfterPcal);
        }
      break;
case START_ALGORITHM:
    pcalStartLength=length;
  canStop=(pcalEndCommentOffset != -1);
state=IN_ALGORITHM;
if (pcalStartOffset != start) {
System.out.println("String_Node_Str");
}
if (!contentType.equals(TLAPartitionScanner.TLA_PCAL)) {
System.out.println("String_Node_Str");
}
break;
case IN_ALGORITHM:
if (contentType.equals(TLAPartitionScanner.TLA_END_PCAL_COMMENT)) {
canStop=(behindLastScannedPosition >= prevAfterPcal);
pcalEndCommentOffset=start;
pcalEndCommentLength=length;
contentType=TLAPartitionScanner.TLA_MULTI_LINE_COMMENT;
state=AFTER_ALGORITHM;
}
 else if (contentType.equals(TLAPartitionScanner.TLA_START_PCAL_COMMENT)) {
System.out.println("String_Node_Str");
}
break;
case AFTER_ALGORITHM:
if (contentType.equals(TLAPartitionScanner.TLA_START_PCAL_COMMENT) || contentType.equals(TLAPartitionScanner.TLA_END_PCAL_COMMENT)) {
System.out.println("String_Node_Str");
}
canStop=canStop || (behindLastScannedPosition >= prevAfterPcal);
break;
default :
System.out.println("String_Node_Str");
}
while (first < category.length) {
TypedPosition p=(TypedPosition)category[first];
if (lastScannedPosition >= p.offset + p.length || (p.overlapsWith(start,length) && (!fDocument.containsPosition(fPositionCategory,start,length) || !contentType.equals(p.getType())))) {
rememberRegion(p.offset,p.length);
fDocument.removePosition(fPositionCategory,p);
++first;
}
 else break;
}
if (fDocument.containsPosition(fPositionCategory,start,length)) {
if ((lastScannedPosition >= e.getOffset() + newLength) && canStop) {
finishScan(state);
return createRegion();
}
++first;
}
 else {
try {
fDocument.addPosition(fPositionCategory,new TypedPosition(start,length,contentType));
rememberRegion(start,length);
}
 catch (BadPositionCategoryException x) {
}
catch (BadLocationException x) {
}
}
token=fScanner.nextToken();
}
finishScan(state);
first=fDocument.computeIndexInCategory(fPositionCategory,behindLastScannedPosition);
clearPositionCache();
category=getPositions();
TypedPosition p;
while (first < category.length) {
p=(TypedPosition)category[first++];
fDocument.removePosition(fPositionCategory,p);
rememberRegion(p.offset,p.length);
}
}
 catch (BadPositionCategoryException x) {
}
catch (BadLocationException x) {
}
 finally {
clearPositionCache();
}
return createRegion();
}