Program: 31168
Project: 31168
Buggy source:
/** 
 * Replace invalid labels in circuit nodes.
 * @param root XML's root
 * @param attrType attribute type (either name or label)
 * @param validLabels map containing valid label values
 */
private static void replaceCircuitNodes(Element root,String attrType,Map<String,String> validLabels,Document doc) throws IllegalArgumentException {
  assert(root != null);
  assert(attrType != null);
  assert(validLabels != null);
  if (validLabels.isEmpty()) {
    return;
  }
switch (attrType) {
case "String_Node_Str":
    for (    Element circElt : XmlIterator.forChildElements(root,"String_Node_Str")) {
      String name=circElt.getAttribute("String_Node_Str");
      if (validLabels.containsKey(name)) {
        circElt.setAttribute("String_Node_Str",validLabels.get(name));
        int replaceCount=0;
        for (        Element attrElt : XmlIterator.forChildElements(circElt,"String_Node_Str")) {
          if (attrElt.hasAttribute("String_Node_Str")) {
            String aName=attrElt.getAttribute("String_Node_Str");
            if (aName.equals("String_Node_Str")) {
              attrElt.setAttribute("String_Node_Str",validLabels.get(name));
              replaceCount++;
            }
          }
        }
        if (replaceCount == 0) {
          Element toAdd=doc.createElement("String_Node_Str");
          toAdd.setAttribute("String_Node_Str","String_Node_Str");
          toAdd.setAttribute("String_Node_Str",validLabels.get(name));
          circElt.appendChild(toAdd);
        }
      }
      for (      Element compElt : XmlIterator.forChildElements(circElt,"String_Node_Str")) {
        if (!compElt.hasAttribute("String_Node_Str")) {
          if (compElt.hasAttribute("String_Node_Str")) {
            String cName=compElt.getAttribute("String_Node_Str");
            if (validLabels.containsKey(cName)) {
              compElt.setAttribute("String_Node_Str",validLabels.get(cName));
              for (              Element attrElt : XmlIterator.forChildElements(compElt,"String_Node_Str")) {
                if (attrElt.hasAttribute("String_Node_Str")) {
                  String aName=attrElt.getAttribute("String_Node_Str");
                  if (aName.equals("String_Node_Str")) {
                    attrElt.setAttribute("String_Node_Str",validLabels.get(name));
                  }
                }
              }
            }
          }
        }
      }
    }
  break;
case "String_Node_Str":
for (Element circElt : XmlIterator.forChildElements(root,"String_Node_Str")) {
  for (  Element attrElt : XmlIterator.forChildElements(circElt,"String_Node_Str")) {
    if (attrElt.hasAttribute("String_Node_Str")) {
      String aName=attrElt.getAttribute("String_Node_Str");
      if (aName.equals("String_Node_Str")) {
        String label=attrElt.getAttribute("String_Node_Str");
        if (validLabels.containsKey(label)) {
          attrElt.setAttribute("String_Node_Str",validLabels.get(label));
        }
      }
    }
  }
}
break;
default :
throw new IllegalArgumentException("String_Node_Str" + attrType + "String_Node_Str");
}
}

Fixed version (ground truth):
/** 
 * Replace invalid labels in circuit nodes.
 * @param root XML's root
 * @param attrType attribute type (either name or label)
 * @param validLabels map containing valid label values
 */
private static void replaceCircuitNodes(Element root,String attrType,Map<String,String> validLabels) throws IllegalArgumentException {
  assert(root != null);
  assert(attrType != null);
  assert(validLabels != null);
  if (validLabels.isEmpty()) {
    return;
  }
switch (attrType) {
case "String_Node_Str":
    for (    Element circElt : XmlIterator.forChildElements(root,"String_Node_Str")) {
      String name=circElt.getAttribute("String_Node_Str");
      if (validLabels.containsKey(name)) {
        circElt.setAttribute("String_Node_Str",validLabels.get(name));
        for (        Element attrElt : XmlIterator.forChildElements(circElt,"String_Node_Str")) {
          if (attrElt.hasAttribute("String_Node_Str")) {
            String aName=attrElt.getAttribute("String_Node_Str");
            if (aName.equals("String_Node_Str")) {
              attrElt.setAttribute("String_Node_Str",validLabels.get(name));
            }
          }
        }
      }
      for (      Element compElt : XmlIterator.forChildElements(circElt,"String_Node_Str")) {
        if (!compElt.hasAttribute("String_Node_Str")) {
          if (compElt.hasAttribute("String_Node_Str")) {
            String cName=compElt.getAttribute("String_Node_Str");
            if (validLabels.containsKey(cName)) {
              compElt.setAttribute("String_Node_Str",validLabels.get(cName));
            }
          }
        }
      }
    }
  break;
case "String_Node_Str":
for (Element circElt : XmlIterator.forChildElements(root,"String_Node_Str")) {
  for (  Element attrElt : XmlIterator.forChildElements(circElt,"String_Node_Str")) {
    if (attrElt.hasAttribute("String_Node_Str")) {
      String aName=attrElt.getAttribute("String_Node_Str");
      if (aName.equals("String_Node_Str")) {
        String label=attrElt.getAttribute("String_Node_Str");
        if (validLabels.containsKey(label)) {
          attrElt.setAttribute("String_Node_Str",validLabels.get(label));
        }
      }
    }
  }
}
break;
default :
throw new IllegalArgumentException("String_Node_Str" + attrType + "String_Node_Str");
}
}