Program: 29438
Project: 29438
Buggy source:
/** 
 * For RawText we need to examine every character. <p>We track an index and an offset into the current RawTextNode (currentRawTextIndex and currentRawTextOffset respectively). 'advance' methods move the index and 'consume' methods optionally move the index and always set the offset == index. (they 'consume' the text between the offset and the index. <p>handle* methods will 'handle the current state' <ul> <li>Precondition : They are in the given state and not at the end of the input <li> Postcondition: They have either advanced the current index or changed states (generally both) </ul> <p>NOTE: a consequence of these conditions is that they are only guaranteed to be able to consume a single character. <p>At the end of visiting a raw text node, all the input will be consumed.
 */
@Override protected void visitRawTextNode(RawTextNode node){
  currentRawTextNode=node;
  currentRawText=node.getRawText();
  currentRawTextOffset=0;
  currentRawTextIndex=0;
  int prevStartIndex=-1;
  while (currentRawTextIndex < currentRawText.length()) {
    int startIndex=currentRawTextIndex;
    if (startIndex != prevStartIndex && currentRawTextNode.missingWhitespaceAt(startIndex)) {
      handleJoinedWhitespace(currentPoint(),false);
    }
    prevStartIndex=startIndex;
    State startState=context.getState();
switch (startState) {
case NONE:
      currentRawTextIndex=currentRawTextOffset=currentRawText.length();
    break;
case PCDATA:
  handlePcData();
break;
case DOUBLE_QUOTED_ATTRIBUTE_VALUE:
handleQuotedAttributeValue(true);
break;
case SINGLE_QUOTED_ATTRIBUTE_VALUE:
handleQuotedAttributeValue(false);
break;
case BEFORE_ATTRIBUTE_VALUE:
handleBeforeAttributeValue();
break;
case AFTER_TAG_NAME_OR_ATTRIBUTE:
handleAfterTagNameOrAttribute();
break;
case BEFORE_ATTRIBUTE_NAME:
handleBeforeAttributeName();
break;
case UNQUOTED_ATTRIBUTE_VALUE:
handleUnquotedAttributeValue();
break;
case AFTER_ATTRIBUTE_NAME:
handleAfterAttributeName();
break;
case HTML_TAG_NAME:
handleHtmlTagName();
break;
case RCDATA_STYLE:
handleRcData(TagName.SpecialTagName.STYLE);
break;
case RCDATA_TITLE:
handleRcData(TagName.SpecialTagName.TITLE);
break;
case RCDATA_SCRIPT:
handleRcData(TagName.SpecialTagName.SCRIPT);
break;
case RCDATA_TEXTAREA:
handleRcData(TagName.SpecialTagName.TEXTAREA);
break;
case CDATA:
handleCData();
break;
case HTML_COMMENT:
handleHtmlComment();
break;
case XML_DECLARATION:
handleXmlDeclaration();
break;
case DOUBLE_QUOTED_XML_ATTRIBUTE_VALUE:
handleXmlAttributeQuoted(true);
break;
case SINGLE_QUOTED_XML_ATTRIBUTE_VALUE:
handleXmlAttributeQuoted(false);
break;
default :
throw new UnsupportedOperationException("String_Node_Str" + startState);
}
if (context.getState() == startState && startIndex == currentRawTextIndex) {
throw new IllegalStateException("String_Node_Str" + startState.name() + "String_Node_Str"+ currentLocation());
}
if (currentRawTextOffset > currentRawTextIndex) {
throw new IllegalStateException("String_Node_Str" + currentRawTextOffset + "String_Node_Str"+ currentRawTextIndex);
}
}
if (currentRawTextIndex != currentRawText.length()) {
throw new AssertionError("String_Node_Str");
}
if (currentRawTextOffset < currentRawTextIndex && currentRawTextOffset != 0) {
RawTextNode suffix=consumeAsRawText();
edits.replace(node,suffix);
}
if (currentRawTextNode.missingWhitespaceAt(currentRawText.length())) {
handleJoinedWhitespace(currentRawTextNode.getSourceLocation().getEndPoint(),true);
}
}

Fixed version (ground truth):
/** 
 * For RawText we need to examine every character. <p>We track an index and an offset into the current RawTextNode (currentRawTextIndex and currentRawTextOffset respectively). 'advance' methods move the index and 'consume' methods optionally move the index and always set the offset == index. (they 'consume' the text between the offset and the index. <p>handle* methods will 'handle the current state' <ul> <li>Precondition : They are in the given state and not at the end of the input <li> Postcondition: They have either advanced the current index or changed states (generally both) </ul> <p>NOTE: a consequence of these conditions is that they are only guaranteed to be able to consume a single character. <p>At the end of visiting a raw text node, all the input will be consumed.
 */
@Override protected void visitRawTextNode(RawTextNode node){
  currentRawTextNode=node;
  currentRawText=node.getRawText();
  currentRawTextOffset=0;
  currentRawTextIndex=0;
  int prevStartIndex=-1;
  while (currentRawTextIndex < currentRawText.length()) {
    int startIndex=currentRawTextIndex;
    if (startIndex != prevStartIndex && currentRawTextNode.missingWhitespaceAt(startIndex)) {
      handleJoinedWhitespace(currentPoint());
    }
    prevStartIndex=startIndex;
    State startState=context.getState();
switch (startState) {
case NONE:
      currentRawTextIndex=currentRawTextOffset=currentRawText.length();
    break;
case PCDATA:
  handlePcData();
break;
case DOUBLE_QUOTED_ATTRIBUTE_VALUE:
handleQuotedAttributeValue(true);
break;
case SINGLE_QUOTED_ATTRIBUTE_VALUE:
handleQuotedAttributeValue(false);
break;
case BEFORE_ATTRIBUTE_VALUE:
handleBeforeAttributeValue();
break;
case AFTER_TAG_NAME_OR_ATTRIBUTE:
handleAfterTagNameOrAttribute();
break;
case BEFORE_ATTRIBUTE_NAME:
handleBeforeAttributeName();
break;
case UNQUOTED_ATTRIBUTE_VALUE:
handleUnquotedAttributeValue();
break;
case AFTER_ATTRIBUTE_NAME:
handleAfterAttributeName();
break;
case HTML_TAG_NAME:
handleHtmlTagName();
break;
case RCDATA_STYLE:
handleRcData(TagName.SpecialTagName.STYLE);
break;
case RCDATA_TITLE:
handleRcData(TagName.SpecialTagName.TITLE);
break;
case RCDATA_SCRIPT:
handleRcData(TagName.SpecialTagName.SCRIPT);
break;
case RCDATA_TEXTAREA:
handleRcData(TagName.SpecialTagName.TEXTAREA);
break;
case CDATA:
handleCData();
break;
case HTML_COMMENT:
handleHtmlComment();
break;
case XML_DECLARATION:
handleXmlDeclaration();
break;
case DOUBLE_QUOTED_XML_ATTRIBUTE_VALUE:
handleXmlAttributeQuoted(true);
break;
case SINGLE_QUOTED_XML_ATTRIBUTE_VALUE:
handleXmlAttributeQuoted(false);
break;
default :
throw new UnsupportedOperationException("String_Node_Str" + startState);
}
if (context.getState() == startState && startIndex == currentRawTextIndex) {
throw new IllegalStateException("String_Node_Str" + startState.name() + "String_Node_Str"+ currentLocation());
}
if (currentRawTextOffset > currentRawTextIndex) {
throw new IllegalStateException("String_Node_Str" + currentRawTextOffset + "String_Node_Str"+ currentRawTextIndex);
}
}
if (currentRawTextIndex != currentRawText.length()) {
throw new AssertionError("String_Node_Str");
}
if (currentRawTextOffset < currentRawTextIndex && currentRawTextOffset != 0) {
RawTextNode suffix=consumeAsRawText();
edits.replace(node,suffix);
}
if (currentRawTextNode.missingWhitespaceAt(currentRawText.length())) {
handleJoinedWhitespace(currentRawTextNode.getSourceLocation().getEndPoint());
}
}