Program: 14016
Project: 14016
Buggy source:
/** 
 * Parses a query with named parameters.  The parameter-index mappings are put into the map, and the parsed query is returned.  DO NOT CALL FROM CLIENT CODE.  This method is non-private so JUnit code can testSelect it.
 * @param query    query to parse
 * @param paramMap map to hold parameter-index mappings
 * @return the parsed query
 */
private static String parse(String query,Map paramMap){
  int length=query.length();
  StringBuffer parsedQuery=new StringBuffer(length);
  boolean inSingleQuote=false;
  boolean inDoubleQuote=false;
  int index=1;
  for (int i=0; i < length; i++) {
    char c=query.charAt(i);
    if (inSingleQuote) {
      if (c == '\'') {
        inSingleQuote=false;
      }
    }
 else     if (inDoubleQuote) {
      if (c == '"') {
        inDoubleQuote=false;
      }
    }
 else {
      if (c == '\'') {
        inSingleQuote=true;
      }
 else       if (c == '"') {
        inDoubleQuote=true;
      }
 else       if (c == ':' && i + 1 < length && Character.isJavaIdentifierStart(query.charAt(i + 1))) {
        int j=i + 2;
        while (j < length && Character.isJavaIdentifierPart(query.charAt(j))) {
          j++;
        }
        String name=query.substring(i + 1,j);
        c='?';
        i+=name.length();
        List indexList=(List)paramMap.get(name);
        if (indexList == null) {
          indexList=new LinkedList();
          paramMap.put(name,indexList);
        }
        indexList.add(new Integer(index));
        index++;
      }
    }
    parsedQuery.append(c);
  }
  for (Iterator itr=paramMap.entrySet().iterator(); itr.hasNext(); ) {
    Map.Entry entry=(Map.Entry)itr.next();
    List list=(List)entry.getValue();
    int[] indexes=new int[list.size()];
    int i=0;
    for (Iterator itr2=list.iterator(); itr2.hasNext(); ) {
      Integer x=(Integer)itr2.next();
      indexes[i++]=x.intValue();
    }
    entry.setValue(indexes);
  }
  return parsedQuery.toString();
}

Fixed version (ground truth):
/** 
 * Parses a query with named parameters.  The parameter-index mappings are put into the map, and the parsed query is returned.  DO NOT CALL FROM CLIENT CODE.  This method is non-private so JUnit code can testSelect it.
 * @param query    query to parse
 * @param paramMap map to hold parameter-index mappings
 * @return the parsed query
 */
private static String parse(String query,Map paramMap){
  int length=query.length();
  StringBuilder parsedQuery=new StringBuilder(length);
  boolean inSingleQuote=false;
  boolean inDoubleQuote=false;
  int index=1;
  char c=' ';
  for (int i=0; i < length; i++) {
    char previousChar=c;
    c=query.charAt(i);
    if (inSingleQuote) {
      if (c == '\'') {
        inSingleQuote=false;
      }
    }
 else     if (inDoubleQuote) {
      if (c == '"') {
        inDoubleQuote=false;
      }
    }
 else {
      if (c == '\'') {
        inSingleQuote=true;
      }
 else       if (c == '"') {
        inDoubleQuote=true;
      }
 else       if (previousChar != ':' && c == ':' && i + 1 < length && Character.isJavaIdentifierStart(query.charAt(i + 1))) {
        int j=i + 2;
        while (j < length && Character.isJavaIdentifierPart(query.charAt(j))) {
          j++;
        }
        String name=query.substring(i + 1,j);
        c='?';
        i+=name.length();
        List indexList=(List)paramMap.get(name);
        if (indexList == null) {
          indexList=new LinkedList();
          paramMap.put(name,indexList);
        }
        indexList.add(Integer.valueOf(index));
        index++;
      }
    }
    parsedQuery.append(c);
  }
  for (Iterator itr=paramMap.entrySet().iterator(); itr.hasNext(); ) {
    Map.Entry entry=(Map.Entry)itr.next();
    List list=(List)entry.getValue();
    int[] indexes=new int[list.size()];
    int i=0;
    for (Iterator itr2=list.iterator(); itr2.hasNext(); ) {
      Integer x=(Integer)itr2.next();
      indexes[i++]=x.intValue();
    }
    entry.setValue(indexes);
  }
  return parsedQuery.toString();
}