Program: 3856
Project: 3856
Buggy source:
/** 
 * Attempts to generate an advanced search based on   {@link SearchInfo} from a  {@link SearchCategory} and encoded composite query string. 
 * @return null if the query could not be parsed otherwise the corresponding {@link SearchInfo}.
 */
public SearchInfo attemptToCreateAdvancedSearch(String query,SearchCategory searchCategory){
  String translatedKeySeparator=getTranslatedKeySeprator();
  String lowerCaseUntranslatedQuery=translator.toLowerCaseEnglish(query);
  String lowerCaseTranslatedQuery=translator.toLowerCaseCurrentLocale(query);
  if (query.indexOf(translatedKeySeparator) > -1) {
    Map<FilePropertyKey,String> map=new HashMap<FilePropertyKey,String>();
    List<KeyPacket> foundKeys=new SortedList<KeyPacket>();
    for (    FilePropertyKey candidateKey : FilePropertyKey.values()) {
      String untranslatedKeyName=FilePropertyKeyUtils.getUntraslatedDisplayName(candidateKey,searchCategory);
      KeyPacket keyPacket=attemptToFindKey(candidateKey,translator.toLowerCaseEnglish(untranslatedKeyName),UNTRANSLATED_SEPARATOR,lowerCaseUntranslatedQuery);
      if (keyPacket != null) {
        foundKeys.add(keyPacket);
        continue;
      }
      if (translator.isCurrentLanguageEnglish()) {
        continue;
      }
      keyPacket=attemptToFindKey(candidateKey,translator.toLowerCaseCurrentLocale(translator.translate(untranslatedKeyName)),translatedKeySeparator,lowerCaseTranslatedQuery);
      if (keyPacket != null) {
        foundKeys.add(keyPacket);
      }
    }
    if (foundKeys.size() == 0) {
      return null;
    }
    if (CHECK_FORMAT) {
      if (query.substring(0,foundKeys.get(0).getStartIndex()).trim().length() > 0) {
        return null;
      }
    }
    for (int i=0; i < foundKeys.size() - 1; i++) {
      attemptToParseValue(query,map,foundKeys.get(i),foundKeys.get(i + 1).startIndex);
    }
    KeyPacket currentPacket=foundKeys.get(foundKeys.size() - 1);
    if (currentPacket.getEndIndex() != query.length()) {
      attemptToParseValue(query,map,currentPacket,query.length());
    }
 else {
      KeyPacket secondLastPacket=foundKeys.get(foundKeys.size() - 2);
      map.remove(secondLastPacket);
      attemptToParseValue(query,map,secondLastPacket,query.length());
    }
    if (map.size() == 0) {
      return null;
    }
    return createAdvancedSearch(map,searchCategory);
  }
  return null;
}

Fixed version (ground truth):
/** 
 * Attempts to generate an advanced search based on   {@link SearchInfo} from a  {@link SearchCategory} and encoded composite query string. 
 * @return null if the query could not be parsed otherwise the corresponding {@link SearchInfo}.
 */
public SearchInfo attemptToCreateAdvancedSearch(String query,SearchCategory searchCategory){
  if (searchCategory == SearchCategory.ALL) {
    return null;
  }
  String translatedKeySeparator=getTranslatedKeySeprator();
  String untranslatedKeySeparator=UNTRANSLATED_SEPARATOR;
  String lowerCaseUntranslatedQuery=translator.toLowerCaseEnglish(query);
  String lowerCaseTranslatedQuery=translator.toLowerCaseCurrentLocale(query);
  if (query.indexOf(translatedKeySeparator) > -1 || query.indexOf(untranslatedKeySeparator) > -1) {
    Map<FilePropertyKey,String> map=new HashMap<FilePropertyKey,String>();
    List<KeyPacket> foundKeys=new SortedList<KeyPacket>();
    for (    FilePropertyKey candidateKey : FilePropertyKey.values()) {
      String untranslatedKeyName=FilePropertyKeyUtils.getUntraslatedDisplayName(candidateKey,searchCategory);
      KeyPacket keyPacket=attemptToFindKey(candidateKey,translator.toLowerCaseEnglish(untranslatedKeyName),untranslatedKeySeparator,lowerCaseUntranslatedQuery);
      if (keyPacket != null) {
        foundKeys.add(keyPacket);
        continue;
      }
      if (translator.isCurrentLanguageEnglish()) {
        continue;
      }
      keyPacket=attemptToFindKey(candidateKey,translator.toLowerCaseCurrentLocale(translator.translate(untranslatedKeyName)),translatedKeySeparator,lowerCaseTranslatedQuery);
      if (keyPacket != null) {
        foundKeys.add(keyPacket);
      }
    }
    if (foundKeys.size() == 0) {
      return null;
    }
    if (CHECK_FORMAT) {
      if (query.substring(0,foundKeys.get(0).getStartIndex()).trim().length() > 0) {
        return null;
      }
    }
    for (int i=0; i < foundKeys.size() - 1; i++) {
      attemptToParseValue(query,map,foundKeys.get(i),foundKeys.get(i + 1).startIndex);
    }
    KeyPacket currentPacket=foundKeys.get(foundKeys.size() - 1);
    if (currentPacket.getEndIndex() != query.length()) {
      attemptToParseValue(query,map,currentPacket,query.length());
    }
 else {
      KeyPacket secondLastPacket=foundKeys.get(foundKeys.size() - 2);
      map.remove(secondLastPacket);
      attemptToParseValue(query,map,secondLastPacket,query.length());
    }
    if (map.size() == 0) {
      return null;
    }
    return createAdvancedSearch(map,searchCategory);
  }
  return null;
}