Program: 96227
Project: 96227
Buggy source:
/** 
 * Gets the sections of text, of the specified CSS nodes.
 * @param css the css text, in it's raw form
 * @param nodes the section nodes we are interested in (ie: .menuitem, *)
 * @param states the section state we are interested in (ie: focus, hover, active). Null (or empty list) means no state.
 */
public static List<CssNode> getSections(String css,String[] nodes,String[] states){
  if (states == null) {
    states=new String[0];
  }
  List<CssNode> sections=new ArrayList<CssNode>();
  for (  String node : nodes) {
    int i=0;
    while (i != -1) {
      i=css.indexOf(node,i);
      if (i > -1) {
        int endOfNodeLabels=css.indexOf("String_Node_Str",i);
        int endOfSection=css.indexOf("String_Node_Str",endOfNodeLabels + 1) + 1;
        int endOfSectionTest=css.indexOf("String_Node_Str",i) + 1;
        if (endOfSection != endOfSectionTest) {
          i=endOfSection;
          continue;
        }
        String nodeLabel=css.substring(i,endOfNodeLabels);
        List<CssAttribute> attributes=new ArrayList<CssAttribute>();
        String nodeSection=css.substring(endOfNodeLabels,endOfSection);
        int start=nodeSection.indexOf('{') + 1;
        while (start != -1) {
          int end=nodeSection.indexOf(';',start);
          if (end != -1) {
            int separator=nodeSection.indexOf(':',start);
            if (separator < end) {
              String key=nodeSection.substring(start,separator);
              String value=nodeSection.substring(separator + 1,end);
              attributes.add(new CssAttribute(key,value));
            }
            start=end + 1;
          }
 else {
            break;
          }
        }
        int multiIndex=nodeLabel.indexOf(',');
        if (multiIndex != -1) {
          multiIndex=0;
          while (multiIndex != -1) {
            int multiEndIndex=nodeLabel.indexOf(',',multiIndex);
            if (multiEndIndex != -1) {
              String newLabel=nodeLabel.substring(multiIndex,multiEndIndex);
              sections.add(new CssNode(newLabel,attributes));
              multiIndex=multiEndIndex + 1;
            }
 else {
              String newLabel=nodeLabel.substring(multiIndex);
              sections.add(new CssNode(newLabel,attributes));
              multiIndex=-1;
            }
          }
        }
 else {
          sections.add(new CssNode(nodeLabel,attributes));
        }
        i=endOfSection;
      }
    }
  }
  for (Iterator<CssNode> iterator=sections.iterator(); iterator.hasNext(); ) {
    final CssNode section=iterator.next();
    String label=section.label;
    boolean canSave=false;
    if (!section.attributes.isEmpty()) {
      main:       for (      String node : nodes) {
        if (label.equals(node)) {
          canSave=true;
          break;
        }
        if (label.length() > node.length() && label.startsWith(node)) {
          int index=node.length();
          label=trim(label.substring(index));
          if (label.charAt(0) == '>') {
            label=label.substring(1);
          }
          for (          String n : nodes) {
            if (n != node && label.startsWith(n)) {
              canSave=true;
              break main;
            }
          }
        }
      }
      if (canSave) {
        int stateIndex=label.lastIndexOf(':');
        if (stateIndex != -1) {
          String stateValue=label.substring(stateIndex + 1);
          boolean saveState=false;
          for (          String state : states) {
            if (stateValue.equals(state)) {
              saveState=true;
              break;
            }
          }
          if (!saveState) {
            canSave=false;
          }
        }
      }
    }
    if (!canSave) {
      iterator.remove();
    }
  }
  for (Iterator<CssNode> iterator=sections.iterator(); iterator.hasNext(); ) {
    final CssNode section=iterator.next();
    if (section != null) {
      String label=section.label;
      for (int i=0; i < sections.size(); i++) {
        final CssNode section2=sections.get(i);
        if (section != section2 && section2 != null && label.equals(section2.label)) {
          sections.set(i,null);
          for (          CssAttribute attribute : section.attributes) {
            for (Iterator<CssAttribute> iterator2=section2.attributes.iterator(); iterator2.hasNext(); ) {
              final CssAttribute attribute2=iterator2.next();
              if (attribute.equals(attribute2)) {
                iterator2.remove();
              }
            }
          }
          section.attributes.addAll(section2.attributes);
        }
      }
    }
 else {
      iterator.remove();
    }
  }
  for (Iterator<CssNode> iterator=sections.iterator(); iterator.hasNext(); ) {
    final CssNode section=iterator.next();
    if (section.attributes.isEmpty()) {
      iterator.remove();
    }
 else {
      for (Iterator<CssAttribute> iterator1=section.attributes.iterator(); iterator1.hasNext(); ) {
        final CssAttribute attribute=iterator1.next();
        if (attribute == null) {
          iterator1.remove();
        }
      }
    }
  }
  if (DEBUG_NODES) {
    for (    CssNode section : sections) {
      System.err.println("String_Node_Str");
      System.err.println(section);
      System.err.println("String_Node_Str");
    }
  }
  return sections;
}

Fixed version (ground truth):
/** 
 * Gets the sections of text, of the specified CSS nodes.
 * @param css the css text, in it's raw form
 * @param nodes the section nodes we are interested in (ie: .menuitem, *)
 * @param states the section state we are interested in (ie: focus, hover, active). Null (or empty list) means no state.
 */
public static List<CssNode> getSections(String css,String[] nodes,String[] states){
  if (states == null) {
    states=new String[0];
  }
  List<CssNode> sections=new ArrayList<CssNode>();
  for (  String node : nodes) {
    int i=0;
    while (i != -1) {
      i=css.indexOf(node,i);
      if (i > -1) {
        int endOfNodeLabels=css.indexOf("String_Node_Str",i);
        int endOfSection=css.indexOf("String_Node_Str",endOfNodeLabels + 1) + 1;
        int endOfSectionTest=css.indexOf("String_Node_Str",i) + 1;
        if (endOfSection != endOfSectionTest) {
          i=endOfSection;
          continue;
        }
        String nodeLabel=css.substring(i,endOfNodeLabels);
        List<CssAttribute> attributes=new ArrayList<CssAttribute>();
        String nodeSection=css.substring(endOfNodeLabels,endOfSection);
        int start=nodeSection.indexOf('{') + 1;
        while (start != -1) {
          int end=nodeSection.indexOf(';',start);
          if (end != -1) {
            int separator=nodeSection.indexOf(':',start);
            if (separator < end) {
              String key=nodeSection.substring(start,separator);
              String value=nodeSection.substring(separator + 1,end);
              if (value.contains("String_Node_Str") || value.contains("String_Node_Str")) {
                end=nodeSection.indexOf(')',end);
                end=nodeSection.indexOf(';',end);
                value=nodeSection.substring(separator + 1,end);
              }
              attributes.add(new CssAttribute(key,value));
            }
            start=end + 1;
          }
 else {
            break;
          }
        }
        int multiIndex=nodeLabel.indexOf(',');
        if (multiIndex != -1) {
          multiIndex=0;
          while (multiIndex != -1) {
            int multiEndIndex=nodeLabel.indexOf(',',multiIndex);
            if (multiEndIndex != -1) {
              String newLabel=nodeLabel.substring(multiIndex,multiEndIndex);
              sections.add(new CssNode(newLabel,attributes));
              multiIndex=multiEndIndex + 1;
            }
 else {
              String newLabel=nodeLabel.substring(multiIndex);
              sections.add(new CssNode(newLabel,attributes));
              multiIndex=-1;
            }
          }
        }
 else {
          sections.add(new CssNode(nodeLabel,attributes));
        }
        i=endOfSection;
      }
    }
  }
  for (Iterator<CssNode> iterator=sections.iterator(); iterator.hasNext(); ) {
    final CssNode section=iterator.next();
    String label=section.label;
    boolean canSave=false;
    if (!section.attributes.isEmpty()) {
      main:       for (      String node : nodes) {
        if (label.equals(node)) {
          canSave=true;
          break;
        }
        if (label.length() > node.length() && label.startsWith(node)) {
          int index=node.length();
          label=trim(label.substring(index));
          if (label.charAt(0) == '>') {
            label=label.substring(1);
          }
          for (          String n : nodes) {
            if (n != node && label.startsWith(n)) {
              canSave=true;
              break main;
            }
          }
        }
      }
      if (canSave) {
        int stateIndex=label.lastIndexOf(':');
        if (stateIndex != -1) {
          String stateValue=label.substring(stateIndex + 1);
          boolean saveState=false;
          for (          String state : states) {
            if (stateValue.equals(state)) {
              saveState=true;
              break;
            }
          }
          if (!saveState) {
            canSave=false;
          }
        }
      }
    }
    if (!canSave) {
      iterator.remove();
    }
  }
  for (Iterator<CssNode> iterator=sections.iterator(); iterator.hasNext(); ) {
    final CssNode section=iterator.next();
    if (section != null) {
      String label=section.label;
      for (int i=0; i < sections.size(); i++) {
        final CssNode section2=sections.get(i);
        if (section != section2 && section2 != null && label.equals(section2.label)) {
          sections.set(i,null);
          for (          CssAttribute attribute : section.attributes) {
            for (Iterator<CssAttribute> iterator2=section2.attributes.iterator(); iterator2.hasNext(); ) {
              final CssAttribute attribute2=iterator2.next();
              if (attribute.equals(attribute2)) {
                iterator2.remove();
              }
            }
          }
          section.attributes.addAll(section2.attributes);
        }
      }
    }
 else {
      iterator.remove();
    }
  }
  for (Iterator<CssNode> iterator=sections.iterator(); iterator.hasNext(); ) {
    final CssNode section=iterator.next();
    if (section.attributes.isEmpty()) {
      iterator.remove();
    }
 else {
      for (Iterator<CssAttribute> iterator1=section.attributes.iterator(); iterator1.hasNext(); ) {
        final CssAttribute attribute=iterator1.next();
        if (attribute == null) {
          iterator1.remove();
        }
      }
    }
  }
  if (DEBUG_NODES) {
    for (    CssNode section : sections) {
      System.err.println("String_Node_Str");
      System.err.println(section);
      System.err.println("String_Node_Str");
    }
  }
  return sections;
}