Program: 39494
Project: 39494
Buggy source:
/** 
 * Parses the selector items.
 * @param selector the selectors in the form of a <code>String</code>
 * @return the resulting list of {@link ICssSelectorItem}
 */
public static List<ICssSelectorItem> parseSelectorItems(String selector){
  List<ICssSelectorItem> selectorItems=new ArrayList<>();
  Matcher itemMatcher=selectorPattern.matcher(selector);
  boolean tagSelectorDescription=false;
  while (itemMatcher.find()) {
    String selectorItem=itemMatcher.group(0);
    char firstChar=selectorItem.charAt(0);
switch (firstChar) {
case '#':
      selectorItems.add(new CssIdSelectorItem(selectorItem.substring(1)));
    break;
case '.':
  selectorItems.add(new CssClassSelectorItem(selectorItem.substring(1)));
break;
case '[':
selectorItems.add(new CssAttributeSelectorItem(selectorItem));
break;
case ':':
selectorItems.add(resolvePseudoSelector(selectorItem));
break;
case ' ':
case '+':
case '>':
case '~':
if (selectorItems.size() == 0) {
throw new IllegalArgumentException(MessageFormatUtil.format("String_Node_Str",firstChar));
}
ICssSelectorItem lastItem=selectorItems.get(selectorItems.size() - 1);
CssSeparatorSelectorItem curItem=new CssSeparatorSelectorItem(firstChar);
if (lastItem instanceof CssSeparatorSelectorItem) {
if (curItem.getSeparator() == ' ') {
break;
}
 else if (((CssSeparatorSelectorItem)lastItem).getSeparator() == ' ') {
selectorItems.set(selectorItems.size() - 1,curItem);
}
 else {
throw new IllegalArgumentException(MessageFormatUtil.format("String_Node_Str",((CssSeparatorSelectorItem)lastItem).getSeparator(),curItem.getSeparator()));
}
}
 else {
selectorItems.add(curItem);
tagSelectorDescription=false;
}
break;
default :
if (tagSelectorDescription) {
throw new IllegalStateException("String_Node_Str");
}
tagSelectorDescription=true;
selectorItems.add(new CssTagSelectorItem(selectorItem));
break;
}
}
if (selectorItems.size() == 0) {
throw new IllegalArgumentException("String_Node_Str");
}
return selectorItems;
}

Fixed version (ground truth):
/** 
 * Parses the selector items.
 * @param selector the selectors in the form of a <code>String</code>
 * @return the resulting list of {@link ICssSelectorItem}
 */
public static List<ICssSelectorItem> parseSelectorItems(String selector){
  List<ICssSelectorItem> selectorItems=new ArrayList<>();
  CssSelectorParserMatch match=new CssSelectorParserMatch(selector,selectorPattern);
  boolean tagSelectorDescription=false;
  while (match.success()) {
    String selectorItem=match.getValue();
    char firstChar=selectorItem.charAt(0);
switch (firstChar) {
case '#':
      match.next();
    selectorItems.add(new CssIdSelectorItem(selectorItem.substring(1)));
  break;
case '.':
match.next();
selectorItems.add(new CssClassSelectorItem(selectorItem.substring(1)));
break;
case '[':
match.next();
selectorItems.add(new CssAttributeSelectorItem(selectorItem));
break;
case ':':
appendPseudoSelector(selectorItems,selectorItem,match);
break;
case ' ':
case '+':
case '>':
case '~':
match.next();
if (selectorItems.size() == 0) {
throw new IllegalArgumentException(MessageFormatUtil.format("String_Node_Str",firstChar));
}
ICssSelectorItem lastItem=selectorItems.get(selectorItems.size() - 1);
CssSeparatorSelectorItem curItem=new CssSeparatorSelectorItem(firstChar);
if (lastItem instanceof CssSeparatorSelectorItem) {
if (curItem.getSeparator() == ' ') {
break;
}
 else if (((CssSeparatorSelectorItem)lastItem).getSeparator() == ' ') {
selectorItems.set(selectorItems.size() - 1,curItem);
}
 else {
throw new IllegalArgumentException(MessageFormatUtil.format("String_Node_Str",((CssSeparatorSelectorItem)lastItem).getSeparator(),curItem.getSeparator()));
}
}
 else {
selectorItems.add(curItem);
tagSelectorDescription=false;
}
break;
default :
match.next();
if (tagSelectorDescription) {
throw new IllegalStateException("String_Node_Str");
}
tagSelectorDescription=true;
selectorItems.add(new CssTagSelectorItem(selectorItem));
break;
}
}
if (selectorItems.size() == 0) {
throw new IllegalArgumentException("String_Node_Str");
}
return selectorItems;
}