Program: 39497
Project: 39497
Buggy source:
private boolean matches(INode element,int lastSelectorItemInd){
  if (!(element instanceof IElementNode)) {
    return false;
  }
  if (lastSelectorItemInd < 0) {
    return true;
  }
  boolean isPseudoElement=element instanceof CssPseudoElementNode;
  for (int i=lastSelectorItemInd; i >= 0; i--) {
    if (isPseudoElement && i < lastSelectorItemInd) {
      element=element.parentNode();
      isPseudoElement=false;
    }
    ICssSelectorItem currentItem=selectorItems.get(i);
    if (currentItem instanceof CssSeparatorSelectorItem) {
      char separator=((CssSeparatorSelectorItem)currentItem).getSeparator();
switch (separator) {
case '>':
        return matches(element.parentNode(),i - 1);
case ' ':
{
        INode parent=element.parentNode();
        while (parent != null) {
          boolean parentMatches=matches(parent,i - 1);
          if (parentMatches) {
            return true;
          }
 else {
            parent=parent.parentNode();
          }
        }
        return false;
      }
case '~':
{
      INode parent=element.parentNode();
      if (parent != null) {
        int indexOfElement=parent.childNodes().indexOf(element);
        for (int j=indexOfElement - 1; j >= 0; j--) {
          if (matches(parent.childNodes().get(j),i - 1)) {
            return true;
          }
        }
      }
      return false;
    }
case '+':
{
    INode parent=element.parentNode();
    if (parent != null) {
      int indexOfElement=parent.childNodes().indexOf(element);
      return indexOfElement > 0 && matches(parent.childNodes().get(indexOfElement - 1),i - 1);
    }
    return false;
  }
default :
return false;
}
}
 else {
if (!currentItem.matches(element)) {
return false;
}
}
}
return true;
}

Fixed version (ground truth):
private boolean matches(INode element,int lastSelectorItemInd){
  if (!(element instanceof IElementNode)) {
    return false;
  }
  if (lastSelectorItemInd < 0) {
    return true;
  }
  boolean isPseudoElement=element instanceof CssPseudoElementNode;
  for (int i=lastSelectorItemInd; i >= 0; i--) {
    if (isPseudoElement && i < lastSelectorItemInd) {
      element=element.parentNode();
      isPseudoElement=false;
    }
    ICssSelectorItem currentItem=selectorItems.get(i);
    if (currentItem instanceof CssSeparatorSelectorItem) {
      char separator=((CssSeparatorSelectorItem)currentItem).getSeparator();
switch (separator) {
case '>':
        return matches(element.parentNode(),i - 1);
case ' ':
{
        INode parent=element.parentNode();
        while (parent != null) {
          boolean parentMatches=matches(parent,i - 1);
          if (parentMatches) {
            return true;
          }
 else {
            parent=parent.parentNode();
          }
        }
        return false;
      }
case '~':
{
      INode parent=element.parentNode();
      if (parent != null) {
        int indexOfElement=parent.childNodes().indexOf(element);
        for (int j=indexOfElement - 1; j >= 0; j--) {
          if (matches(parent.childNodes().get(j),i - 1)) {
            return true;
          }
        }
      }
      return false;
    }
case '+':
{
    INode parent=element.parentNode();
    if (parent != null) {
      int indexOfElement=parent.childNodes().indexOf(element);
      INode previousElement=null;
      for (int j=indexOfElement - 1; j >= 0; j--)       if (parent.childNodes().get(j) instanceof IElementNode) {
        previousElement=parent.childNodes().get(j);
        break;
      }
      if (previousElement != null)       return indexOfElement > 0 && matches(previousElement,i - 1);
    }
    return false;
  }
default :
return false;
}
}
 else {
if (!currentItem.matches(element)) {
return false;
}
}
}
return true;
}