Program: 51958
Project: 51958
Buggy source:
public void processOverlay(String overlaySrc,org.pentaho.ui.xul.dom.Document targetDocument,XulDomContainer container) throws XulException {
  InputStream in=getInputStreamForSrc(overlaySrc);
  Document doc=null;
  ResourceBundle res=null;
  try {
    res=ResourceBundle.getBundle(overlaySrc.replace("String_Node_Str","String_Node_Str"));
    if (res == null) {
      res=ResourceBundle.getBundle((this.getRootDir() + overlaySrc).replace("String_Node_Str","String_Node_Str"));
      if (res == null) {
        logger.error("String_Node_Str");
        res=mainBundle;
      }
    }
  }
 catch (  MissingResourceException e) {
    logger.warn("String_Node_Str" + overlaySrc);
  }
  String runningTranslatedOutput=getDocFromInputStream(in).asXML();
  if (res != null) {
    try {
      runningTranslatedOutput=ResourceBundleTranslator.translate(runningTranslatedOutput,res);
    }
 catch (    IOException e) {
      logger.error("String_Node_Str" + overlaySrc,e);
    }
  }
  if (this.mainBundle != null) {
    try {
      runningTranslatedOutput=ResourceBundleTranslator.translate(runningTranslatedOutput,this.mainBundle);
      try {
        SAXReader rdr=new SAXReader();
        String upperedIdDoc=this.upperCaseIDAttrs(runningTranslatedOutput.toString());
        doc=rdr.read(new StringReader(upperedIdDoc));
      }
 catch (      DocumentException e) {
        logger.error("String_Node_Str",e);
      }
    }
 catch (    IOException e) {
      logger.error("String_Node_Str",e);
    }
  }
 else {
    try {
      SAXReader rdr=new SAXReader();
      String upperedIdDoc=this.upperCaseIDAttrs(runningTranslatedOutput.toString());
      doc=rdr.read(new StringReader(upperedIdDoc));
    }
 catch (    DocumentException e) {
      logger.error("String_Node_Str",e);
    }
  }
  Element overlayRoot=doc.getRootElement();
  for (  Object child : overlayRoot.elements()) {
    Element overlay=(Element)child;
    String overlayId=overlay.attributeValue("String_Node_Str");
    org.pentaho.ui.xul.dom.Element sourceElement=targetDocument.getElementById(overlayId);
    if (sourceElement == null) {
      logger.warn("String_Node_Str" + overlayId + "String_Node_Str");
      continue;
    }
    for (    Object childToParse : overlay.elements()) {
      Element childElement=(Element)childToParse;
      logger.info("String_Node_Str" + overlayId);
      parser.reset();
      parser.setContainer(container);
      XulComponent c=parser.parse(childElement,(XulContainer)sourceElement);
      String insertBefore=childElement.attributeValue("String_Node_Str");
      String insertAfter=childElement.attributeValue("String_Node_Str");
      String position=childElement.attributeValue("String_Node_Str");
      XulContainer sourceContainer=((XulContainer)sourceElement);
      int positionToInsert=-1;
      if (insertBefore != null) {
        org.pentaho.ui.xul.dom.Element insertBeforeTarget=targetDocument.getElementById(insertBefore);
        positionToInsert=sourceContainer.getChildNodes().indexOf(insertBeforeTarget);
      }
 else       if (insertAfter != null) {
        org.pentaho.ui.xul.dom.Element insertAfterTarget=targetDocument.getElementById(insertAfter);
        positionToInsert=sourceContainer.getChildNodes().indexOf(insertAfterTarget);
      }
 else       if (position != null) {
        int pos=Integer.parseInt(position);
        positionToInsert=(pos <= sourceContainer.getChildNodes().size()) ? pos : -1;
      }
      if (positionToInsert == -1) {
        positionToInsert=sourceContainer.getChildNodes().size();
      }
      sourceContainer.addComponentAt(c,positionToInsert);
      sourceContainer.addChildAt(c,positionToInsert);
      logger.info("String_Node_Str" + c);
    }
    List attribs=overlay.attributes();
    for (    Object o : attribs) {
      Attribute atr=(Attribute)o;
      try {
        BeanUtils.setProperty(sourceElement,atr.getName(),atr.getValue());
      }
 catch (      InvocationTargetException e) {
        logger.error(e);
      }
catch (      IllegalAccessException e) {
        logger.error(e);
      }
    }
  }
}

Fixed version (ground truth):
public void processOverlay(String overlaySrc,org.pentaho.ui.xul.dom.Document targetDocument,XulDomContainer container) throws XulException {
  InputStream in=getInputStreamForSrc(overlaySrc);
  Document doc=null;
  ResourceBundle res=null;
  try {
    res=ResourceBundle.getBundle(overlaySrc.replace("String_Node_Str","String_Node_Str"));
    if (res == null) {
      res=ResourceBundle.getBundle((this.getRootDir() + overlaySrc).replace("String_Node_Str","String_Node_Str"));
      if (res == null) {
        logger.error("String_Node_Str");
        res=mainBundle;
      }
    }
  }
 catch (  MissingResourceException e) {
    logger.warn("String_Node_Str" + overlaySrc);
  }
  String runningTranslatedOutput=getDocFromInputStream(in).asXML();
  if (res != null) {
    try {
      runningTranslatedOutput=ResourceBundleTranslator.translate(runningTranslatedOutput,res);
    }
 catch (    IOException e) {
      logger.error("String_Node_Str" + overlaySrc,e);
    }
  }
  if (this.mainBundle != null) {
    try {
      runningTranslatedOutput=ResourceBundleTranslator.translate(runningTranslatedOutput,this.mainBundle);
      try {
        SAXReader rdr=new SAXReader();
        String upperedIdDoc=this.upperCaseIDAttrs(runningTranslatedOutput.toString());
        doc=rdr.read(new StringReader(upperedIdDoc));
      }
 catch (      DocumentException e) {
        logger.error("String_Node_Str",e);
      }
    }
 catch (    IOException e) {
      logger.error("String_Node_Str",e);
    }
  }
 else {
    try {
      SAXReader rdr=new SAXReader();
      String upperedIdDoc=this.upperCaseIDAttrs(runningTranslatedOutput.toString());
      doc=rdr.read(new StringReader(upperedIdDoc));
    }
 catch (    DocumentException e) {
      logger.error("String_Node_Str",e);
    }
  }
  Element overlayRoot=doc.getRootElement();
  for (  Object child : overlayRoot.elements()) {
    Element overlay=(Element)child;
    String overlayId=overlay.attributeValue("String_Node_Str");
    org.pentaho.ui.xul.dom.Element sourceElement=targetDocument.getElementById(overlayId);
    if (sourceElement == null) {
      logger.warn("String_Node_Str" + overlayId + "String_Node_Str");
      continue;
    }
    for (    Object childToParse : overlay.elements()) {
      Element childElement=(Element)childToParse;
      logger.info("String_Node_Str" + overlayId);
      parser.reset();
      parser.setContainer(container);
      XulComponent c=parser.parse(childElement,(XulContainer)sourceElement);
      String insertBefore=childElement.attributeValue("String_Node_Str");
      String insertAfter=childElement.attributeValue("String_Node_Str");
      String position=childElement.attributeValue("String_Node_Str");
      XulContainer sourceContainer=((XulContainer)sourceElement);
      int positionToInsert=-1;
      if (insertBefore != null) {
        org.pentaho.ui.xul.dom.Element insertBeforeTarget=targetDocument.getElementById(insertBefore);
        positionToInsert=sourceContainer.getChildNodes().indexOf(insertBeforeTarget);
      }
 else       if (insertAfter != null) {
        org.pentaho.ui.xul.dom.Element insertAfterTarget=targetDocument.getElementById(insertAfter);
        positionToInsert=sourceContainer.getChildNodes().indexOf(insertAfterTarget);
      }
 else       if (position != null) {
        int pos=Integer.parseInt(position);
        positionToInsert=(pos <= sourceContainer.getChildNodes().size()) ? pos : -1;
      }
      if (positionToInsert == -1 || positionToInsert == sourceContainer.getChildNodes().size()) {
        sourceContainer.addComponent(c);
        sourceContainer.addChild(c);
      }
 else {
        sourceContainer.addComponentAt(c,positionToInsert);
        sourceContainer.addChildAt(c,positionToInsert);
      }
      logger.info("String_Node_Str" + c);
    }
    List attribs=overlay.attributes();
    for (    Object o : attribs) {
      Attribute atr=(Attribute)o;
      try {
        BeanUtils.setProperty(sourceElement,atr.getName(),atr.getValue());
      }
 catch (      InvocationTargetException e) {
        logger.error(e);
      }
catch (      IllegalAccessException e) {
        logger.error(e);
      }
    }
  }
}