Program: 244
Project: 244
Buggy source:
/** 
 * Parse the text entered by the user. This does not include the leading colon.
 * @param cmd The user entered text
 * @return The parse result
 * @throws ExException if the text is syntactically incorrect
 */
public ParseResult parse(String cmd) throws ExException {
  logger.debug("String_Node_Str" + cmd + "String_Node_Str");
  int state=STATE_START;
  Ranges ranges=new Ranges();
  StringBuffer command=new StringBuffer();
  StringBuffer argument=new StringBuffer();
  StringBuffer location=null;
  int offsetSign=1;
  int offsetNumber=0;
  int offsetTotal=0;
  boolean move=false;
  char patternType=0;
  int backCount=0;
  boolean inBrackets=false;
  for (int i=0; i <= cmd.length(); i++) {
    boolean reprocess=true;
    char ch=(i == cmd.length() ? '\n' : cmd.charAt(i));
    while (reprocess) {
switch (state) {
case STATE_START:
        if (Character.isLetter(ch) || "String_Node_Str".indexOf(ch) >= 0) {
          state=STATE_COMMAND;
        }
 else {
          state=STATE_RANGE;
        }
      break;
case STATE_COMMAND:
    if (Character.isLetter(ch) || (command.length() == 0 && "String_Node_Str".indexOf(ch) >= 0) || (command.length() > 0 && ch == command.charAt(command.length() - 1) && "String_Node_Str".indexOf(ch) >= 0)) {
      command.append(ch);
      reprocess=false;
      if (!Character.isLetter(ch)) {
        state=STATE_CMD_ARG;
      }
    }
 else {
      state=STATE_CMD_ARG;
    }
  break;
case STATE_CMD_ARG:
argument.append(ch);
reprocess=false;
break;
case STATE_RANGE:
location=new StringBuffer();
offsetTotal=0;
offsetNumber=0;
move=false;
if (ch >= '0' && ch <= '9') {
state=STATE_RANGE_LINE;
}
 else if (ch == '.') {
state=STATE_RANGE_CURRENT;
}
 else if (ch == '$') {
state=STATE_RANGE_LAST;
}
 else if (ch == '%') {
state=STATE_RANGE_ALL;
}
 else if (ch == '\'') {
state=STATE_RANGE_MARK;
}
 else if (ch == '+' || ch == '-') {
state=STATE_RANGE_OFFSET;
}
 else if (ch == '\\') {
location.append(ch);
state=STATE_RANGE_SHORT_PATTERN;
reprocess=false;
}
 else if (ch == '/' || ch == '?') {
location.append(ch);
patternType=ch;
backCount=0;
inBrackets=false;
state=STATE_RANGE_PATTERN;
reprocess=false;
}
 else {
state=STATE_ERROR;
reprocess=false;
}
break;
case STATE_RANGE_SHORT_PATTERN:
if (ch == '/' || ch == '?' || ch == '&') {
location.append(ch);
state=STATE_RANGE_PATTERN_MAYBE_DONE;
reprocess=false;
}
 else {
state=STATE_ERROR;
reprocess=false;
}
break;
case STATE_RANGE_PATTERN:
if (ch == '\n') {
location.append(patternType);
state=STATE_RANGE_MAYBE_DONE;
}
 else {
location.append(ch);
if (ch == '[' && !inBrackets) {
inBrackets=true;
}
 else if (ch == ']' && inBrackets && !(location.charAt(location.length() - 2) == '[' || (location.length() >= 3 && location.substring(location.length() - 3).equals("String_Node_Str")))) {
inBrackets=false;
}
 else if (ch == '\\') {
backCount++;
}
 else if (ch == patternType && !inBrackets && (location.charAt(location.length() - 2) != '\\' || backCount % 2 == 0)) {
state=STATE_RANGE_PATTERN_MAYBE_DONE;
}
if (ch != '\\') {
backCount=0;
}
reprocess=false;
}
break;
case STATE_RANGE_PATTERN_MAYBE_DONE:
if (ch == '/' || ch == '?') {
location.append('\u0000');
location.append(ch);
patternType=ch;
backCount=0;
inBrackets=false;
state=STATE_RANGE_PATTERN;
reprocess=false;
}
 else {
state=STATE_RANGE_MAYBE_DONE;
}
break;
case STATE_RANGE_LINE:
if (ch >= '0' && ch <= '9') {
location.append(ch);
state=STATE_RANGE_MAYBE_DONE;
reprocess=false;
}
 else {
state=STATE_RANGE_MAYBE_DONE;
}
break;
case STATE_RANGE_CURRENT:
location.append(ch);
state=STATE_RANGE_MAYBE_DONE;
reprocess=false;
break;
case STATE_RANGE_LAST:
location.append(ch);
state=STATE_RANGE_MAYBE_DONE;
reprocess=false;
break;
case STATE_RANGE_ALL:
location.append(ch);
state=STATE_RANGE_MAYBE_DONE;
reprocess=false;
break;
case STATE_RANGE_MARK:
location.append(ch);
state=STATE_RANGE_MARK_CHAR;
reprocess=false;
break;
case STATE_RANGE_MARK_CHAR:
location.append(ch);
state=STATE_RANGE_MAYBE_DONE;
reprocess=false;
break;
case STATE_RANGE_DONE:
Range[] range=AbstractRange.createRange(location.toString(),offsetTotal,move);
ranges.addRange(range);
if (ch == ':' || ch == '\n') {
state=STATE_COMMAND;
reprocess=false;
}
 else if (Character.isLetter(ch) || "String_Node_Str".indexOf(ch) >= 0) {
state=STATE_COMMAND;
}
 else {
state=STATE_RANGE;
}
break;
case STATE_RANGE_MAYBE_DONE:
if (ch == '+' || ch == '-') {
state=STATE_RANGE_OFFSET;
}
 else if (ch == ',' || ch == ';') {
state=STATE_RANGE_SEPARATOR;
}
 else if (ch >= '0' && ch <= '9') {
state=STATE_RANGE_LINE;
}
 else {
state=STATE_RANGE_DONE;
}
break;
case STATE_RANGE_OFFSET:
offsetNumber=0;
if (ch == '+') {
offsetSign=1;
}
 else if (ch == '-') {
offsetSign=-1;
}
state=STATE_RANGE_OFFSET_MAYBE_DONE;
reprocess=false;
break;
case STATE_RANGE_OFFSET_MAYBE_DONE:
if (ch >= '0' && ch <= '9') {
state=STATE_RANGE_OFFSET_NUM;
}
 else {
state=STATE_RANGE_OFFSET_DONE;
}
break;
case STATE_RANGE_OFFSET_DONE:
if (offsetNumber == 0) {
offsetNumber=1;
}
offsetTotal+=offsetNumber * offsetSign;
if (ch == '+' || ch == '-') {
state=STATE_RANGE_OFFSET;
}
 else {
state=STATE_RANGE_MAYBE_DONE;
}
break;
case STATE_RANGE_OFFSET_NUM:
if (ch >= '0' && ch <= '9') {
offsetNumber=offsetNumber * 10 + (ch - '0');
state=STATE_RANGE_OFFSET_MAYBE_DONE;
reprocess=false;
}
 else if (ch == '+' || ch == '-') {
state=STATE_RANGE_OFFSET_DONE;
}
 else {
state=STATE_RANGE_OFFSET_MAYBE_DONE;
}
break;
case STATE_RANGE_SEPARATOR:
if (ch == ',') {
move=false;
}
 else if (ch == ';') {
move=true;
}
state=STATE_RANGE_DONE;
reprocess=false;
break;
}
}
if (state == STATE_ERROR) {
throw new InvalidCommandException(cmd);
}
}
logger.debug("String_Node_Str" + ranges);
logger.debug("String_Node_Str" + command);
logger.debug("String_Node_Str" + argument);
return new ParseResult(ranges,command.toString(),argument.toString().trim());
}

Fixed version (ground truth):
/** 
 * Parse the text entered by the user. This does not include the leading colon.
 * @param cmd The user entered text
 * @return The parse result
 * @throws ExException if the text is syntactically incorrect
 */
public ParseResult parse(String cmd) throws ExException {
  logger.debug("String_Node_Str" + cmd + "String_Node_Str");
  int state=STATE_START;
  Ranges ranges=new Ranges();
  StringBuffer command=new StringBuffer();
  StringBuffer argument=new StringBuffer();
  StringBuffer location=null;
  int offsetSign=1;
  int offsetNumber=0;
  int offsetTotal=0;
  boolean move=false;
  char patternType=0;
  int backCount=0;
  boolean inBrackets=false;
  for (int i=0; i <= cmd.length(); i++) {
    boolean reprocess=true;
    char ch=(i == cmd.length() ? '\n' : cmd.charAt(i));
    while (reprocess) {
switch (state) {
case STATE_START:
        if (Character.isLetter(ch) || "String_Node_Str".indexOf(ch) >= 0) {
          state=STATE_COMMAND;
        }
 else {
          state=STATE_RANGE;
        }
      break;
case STATE_COMMAND:
    if (Character.isLetter(ch) || (command.length() == 0 && "String_Node_Str".indexOf(ch) >= 0) || (command.length() > 0 && ch == command.charAt(command.length() - 1) && "String_Node_Str".indexOf(ch) >= 0)) {
      command.append(ch);
      reprocess=false;
      if (!Character.isLetter(ch)) {
        state=STATE_CMD_ARG;
      }
    }
 else {
      state=STATE_CMD_ARG;
    }
  break;
case STATE_CMD_ARG:
argument.append(ch);
reprocess=false;
break;
case STATE_RANGE:
location=new StringBuffer();
offsetTotal=0;
offsetNumber=0;
move=false;
if (ch >= '0' && ch <= '9') {
state=STATE_RANGE_LINE;
}
 else if (ch == '.') {
state=STATE_RANGE_CURRENT;
}
 else if (ch == '$') {
state=STATE_RANGE_LAST;
}
 else if (ch == '%') {
state=STATE_RANGE_ALL;
}
 else if (ch == '\'') {
state=STATE_RANGE_MARK;
}
 else if (ch == '+' || ch == '-') {
location.append('0');
state=STATE_RANGE_OFFSET;
}
 else if (ch == '\\') {
location.append(ch);
state=STATE_RANGE_SHORT_PATTERN;
reprocess=false;
}
 else if (ch == '/' || ch == '?') {
location.append(ch);
patternType=ch;
backCount=0;
inBrackets=false;
state=STATE_RANGE_PATTERN;
reprocess=false;
}
 else {
state=STATE_ERROR;
reprocess=false;
}
break;
case STATE_RANGE_SHORT_PATTERN:
if (ch == '/' || ch == '?' || ch == '&') {
location.append(ch);
state=STATE_RANGE_PATTERN_MAYBE_DONE;
reprocess=false;
}
 else {
state=STATE_ERROR;
reprocess=false;
}
break;
case STATE_RANGE_PATTERN:
if (ch == '\n') {
location.append(patternType);
state=STATE_RANGE_MAYBE_DONE;
}
 else {
location.append(ch);
if (ch == '[' && !inBrackets) {
inBrackets=true;
}
 else if (ch == ']' && inBrackets && !(location.charAt(location.length() - 2) == '[' || (location.length() >= 3 && location.substring(location.length() - 3).equals("String_Node_Str")))) {
inBrackets=false;
}
 else if (ch == '\\') {
backCount++;
}
 else if (ch == patternType && !inBrackets && (location.charAt(location.length() - 2) != '\\' || backCount % 2 == 0)) {
state=STATE_RANGE_PATTERN_MAYBE_DONE;
}
if (ch != '\\') {
backCount=0;
}
reprocess=false;
}
break;
case STATE_RANGE_PATTERN_MAYBE_DONE:
if (ch == '/' || ch == '?') {
location.append('\u0000');
location.append(ch);
patternType=ch;
backCount=0;
inBrackets=false;
state=STATE_RANGE_PATTERN;
reprocess=false;
}
 else {
state=STATE_RANGE_MAYBE_DONE;
}
break;
case STATE_RANGE_LINE:
if (ch >= '0' && ch <= '9') {
location.append(ch);
state=STATE_RANGE_MAYBE_DONE;
reprocess=false;
}
 else {
state=STATE_RANGE_MAYBE_DONE;
}
break;
case STATE_RANGE_CURRENT:
location.append(ch);
state=STATE_RANGE_MAYBE_DONE;
reprocess=false;
break;
case STATE_RANGE_LAST:
location.append(ch);
state=STATE_RANGE_MAYBE_DONE;
reprocess=false;
break;
case STATE_RANGE_ALL:
location.append(ch);
state=STATE_RANGE_MAYBE_DONE;
reprocess=false;
break;
case STATE_RANGE_MARK:
location.append(ch);
state=STATE_RANGE_MARK_CHAR;
reprocess=false;
break;
case STATE_RANGE_MARK_CHAR:
location.append(ch);
state=STATE_RANGE_MAYBE_DONE;
reprocess=false;
break;
case STATE_RANGE_DONE:
Range[] range=AbstractRange.createRange(location.toString(),offsetTotal,move);
ranges.addRange(range);
if (ch == ':' || ch == '\n') {
state=STATE_COMMAND;
reprocess=false;
}
 else if (Character.isLetter(ch) || "String_Node_Str".indexOf(ch) >= 0) {
state=STATE_COMMAND;
}
 else {
state=STATE_RANGE;
}
break;
case STATE_RANGE_MAYBE_DONE:
if (ch == '+' || ch == '-') {
state=STATE_RANGE_OFFSET;
}
 else if (ch == ',' || ch == ';') {
state=STATE_RANGE_SEPARATOR;
}
 else if (ch >= '0' && ch <= '9') {
state=STATE_RANGE_LINE;
}
 else {
state=STATE_RANGE_DONE;
}
break;
case STATE_RANGE_OFFSET:
offsetNumber=0;
if (ch == '+') {
offsetSign=1;
}
 else if (ch == '-') {
offsetSign=-1;
}
state=STATE_RANGE_OFFSET_MAYBE_DONE;
reprocess=false;
break;
case STATE_RANGE_OFFSET_MAYBE_DONE:
if (ch >= '0' && ch <= '9') {
state=STATE_RANGE_OFFSET_NUM;
}
 else {
state=STATE_RANGE_OFFSET_DONE;
}
break;
case STATE_RANGE_OFFSET_DONE:
if (offsetNumber == 0) {
offsetNumber=1;
}
offsetTotal+=offsetNumber * offsetSign;
if (ch == '+' || ch == '-') {
state=STATE_RANGE_OFFSET;
}
 else {
state=STATE_RANGE_MAYBE_DONE;
}
break;
case STATE_RANGE_OFFSET_NUM:
if (ch >= '0' && ch <= '9') {
offsetNumber=offsetNumber * 10 + (ch - '0');
state=STATE_RANGE_OFFSET_MAYBE_DONE;
reprocess=false;
}
 else if (ch == '+' || ch == '-') {
state=STATE_RANGE_OFFSET_DONE;
}
 else {
state=STATE_RANGE_OFFSET_MAYBE_DONE;
}
break;
case STATE_RANGE_SEPARATOR:
if (ch == ',') {
move=false;
}
 else if (ch == ';') {
move=true;
}
state=STATE_RANGE_DONE;
reprocess=false;
break;
}
}
if (state == STATE_ERROR) {
throw new InvalidCommandException(cmd);
}
}
logger.debug("String_Node_Str" + ranges);
logger.debug("String_Node_Str" + command);
logger.debug("String_Node_Str" + argument);
return new ParseResult(ranges,command.toString(),argument.toString().trim());
}