Program: 45225
Project: 45225
Buggy source:
/** 
 * Parses the specified command and stores the result in <code>tokens</code>. <p> The <code>tokenTypes</code> argument is optional, and can be set to <code>null</code>. If not set to null, it will contain instructions about whether a keyword is declared in the token of the same index.<br/> For example, if <code>tokenTypes[i] == true</code>, then <code>tokens[i]</code> contains a keyword. </p> <p> This method is very lax about syntax. Errors are just ignored, and a best effort will be made to make sense of the rest of the command. </p> <p> When not sure about how many tokens compose the command - which should be pretty much all the time, it is advised to allocate <code>command.length()</code> big arrays. While not very memory efficient, this is the only way to ensure success. This is an implementation design: growing the size of the buffer to fit the actual number of tokens is resource consuming, both in terms of CPU and memory. The 'use the maximum amount of memory that makes sense' is the lesser of two evils. </p>
 * @param command    command to parse.
 * @param tokens     where to store the tokens that compose the command.
 * @param tokenTypes optional array in which to store information about potential keywords.
 * @return            the number of tokens that were found.
 */
private static int parse(String command,String[] tokens,boolean[] tokenTypes){
  char[] buffer;
  int tokenIndex;
  StringBuffer currentToken;
  boolean isInQuotes;
  command=command.trim();
  currentToken=new StringBuffer(command.length());
  tokenIndex=0;
  buffer=command.toCharArray();
  isInQuotes=false;
  for (int i=0; i < command.length(); i++) {
    if (buffer[i] == '\"') {
      currentToken.append(buffer[i]);
      isInQuotes=!isInQuotes;
    }
 else     if (buffer[i] == '\\') {
      currentToken.append(buffer[i]);
      if (i + 1 != command.length())       currentToken.append(buffer[++i]);
    }
 else     if (buffer[i] == ' ' && !isInQuotes) {
      while (i + 1 < command.length() && buffer[i + 1] == ' ')       i++;
      tokens[tokenIndex]=currentToken.toString();
      tokenIndex++;
      currentToken.setLength(0);
    }
 else     if (buffer[i] == KEYWORD_HEADER) {
      currentToken.append(KEYWORD_HEADER);
      if (++i != command.length()) {
        if (tokenTypes != null)         if (buffer[i] == KEYWORD_PATH || buffer[i] == KEYWORD_NAME || buffer[i] == KEYWORD_PARENT || buffer[i] == KEYWORD_VM_PATH)         tokenTypes[tokenIndex]=true;
        currentToken.append(buffer[i]);
      }
    }
 else     currentToken.append(buffer[i]);
  }
  if (currentToken.length() != 0) {
    tokens[tokenIndex]=currentToken.toString();
    return tokenIndex + 1;
  }
  return tokenIndex;
}

Fixed version (ground truth):
/** 
 * Parses the specified command and stores the result in <code>tokens</code>. <p> The <code>tokenTypes</code> argument is optional, and can be set to <code>null</code>. If not set to null, it will contain instructions about whether a keyword is declared in the token of the same index.<br/> For example, if <code>tokenTypes[i] == true</code>, then <code>tokens[i]</code> contains a keyword. </p> <p> This method is very lax about syntax. Errors are just ignored, and a best effort will be made to make sense of the rest of the command. </p> <p> When not sure about how many tokens compose the command - which should be pretty much all the time, it is advised to allocate <code>command.length()</code> big arrays. While not very memory efficient, this is the only way to ensure success. This is an implementation design: growing the size of the buffer to fit the actual number of tokens is resource consuming, both in terms of CPU and memory. The 'use the maximum amount of memory that makes sense' is the lesser of two evils. </p>
 * @param command    command to parse.
 * @param tokens     where to store the tokens that compose the command.
 * @param tokenTypes optional array in which to store information about potential keywords.
 * @return            the number of tokens that were found.
 */
private static int parse(String command,String[] tokens,boolean[] tokenTypes){
  char[] buffer;
  int tokenIndex;
  StringBuffer currentToken;
  boolean isInQuotes;
  command=command.trim();
  currentToken=new StringBuffer(command.length());
  tokenIndex=0;
  buffer=command.toCharArray();
  isInQuotes=false;
  for (int i=0; i < command.length(); i++) {
    if (buffer[i] == '\"') {
      currentToken.append(buffer[i]);
      isInQuotes=!isInQuotes;
    }
 else     if (buffer[i] == '\\') {
      if (i + 1 != command.length())       currentToken.append(buffer[++i]);
    }
 else     if (buffer[i] == ' ' && !isInQuotes) {
      while (i + 1 < command.length() && buffer[i + 1] == ' ')       i++;
      tokens[tokenIndex]=currentToken.toString();
      tokenIndex++;
      currentToken.setLength(0);
    }
 else     if (buffer[i] == KEYWORD_HEADER) {
      currentToken.append(KEYWORD_HEADER);
      if (++i != command.length()) {
        if (tokenTypes != null)         if (buffer[i] == KEYWORD_PATH || buffer[i] == KEYWORD_NAME || buffer[i] == KEYWORD_PARENT || buffer[i] == KEYWORD_VM_PATH)         tokenTypes[tokenIndex]=true;
        currentToken.append(buffer[i]);
      }
    }
 else     currentToken.append(buffer[i]);
  }
  if (currentToken.length() != 0) {
    tokens[tokenIndex]=currentToken.toString();
    return tokenIndex + 1;
  }
  return tokenIndex;
}