Program: 148020
Project: 148020
Buggy source:
public Element getParentElement(TreeObject treeObj){
  if (!(treeObj instanceof TreeParent))   return null;
  Element elemFolder=null;
  String xpath=getXPathForTreeObject(treeObj);
  Document doc=credentials.get(UnifyUrl(treeObj.getServerRoot().getWsKey().toString())).doc;
  if (doc.selectNodes(xpath).isEmpty()) {
    xpath=xpath.replaceAll("String_Node_Str","String_Node_Str");
    if (doc.selectNodes(xpath).isEmpty())     xpath=getXPathForTreeObject(treeObj.getParent() != null ? treeObj.getParent() : treeObj.getServerRoot());
    if (xpath != null) {
      Element elemTop=null;
      if (doc.selectNodes(xpath).isEmpty()) {
        elemTop=getTopElementWithUser(treeObj.getServerRoot().getUser().getUsername(),UnifyUrl(treeObj.getServerRoot().getWsKey().toString()));
      }
 else {
        if (treeObj.getType() == TreeObject.TRANSFORMER && treeObj.getParent() == null) {
          xpath+="String_Node_Str";
        }
        elemTop=(Element)doc.selectNodes(xpath).get(0);
      }
      String selPath="String_Node_Str" + filterOutBlank(treeObj.getDisplayName()) + "String_Node_Str"+ treeObj.getType()+ "String_Node_Str";
      if (elemTop.selectNodes(selPath).isEmpty()) {
        elemFolder=elemTop.addElement(filterOutBlank(treeObj.getDisplayName()));
        elemFolder.setText(treeObj.getType() + "String_Node_Str");
      }
 else {
        elemFolder=(Element)elemTop.selectNodes(selPath).get(0);
      }
    }
  }
 else {
    elemFolder=(Element)doc.selectNodes(xpath).get(0);
  }
  return elemFolder;
}

Fixed version (ground truth):
public Element getParentElement(TreeObject treeObj){
  if (!(treeObj instanceof TreeParent))   return null;
  Element elemFolder=null;
  String xpath=getXPathForTreeObject(treeObj);
  if (credentials.get(UnifyUrl(treeObj.getServerRoot().getWsKey().toString())) == null) {
    return null;
  }
  Document doc=credentials.get(UnifyUrl(treeObj.getServerRoot().getWsKey().toString())).doc;
  if (doc.selectNodes(xpath).isEmpty()) {
    xpath=xpath.replaceAll("String_Node_Str","String_Node_Str");
    if (doc.selectNodes(xpath).isEmpty())     xpath=getXPathForTreeObject(treeObj.getParent() != null ? treeObj.getParent() : treeObj.getServerRoot());
    if (xpath != null) {
      Element elemTop=null;
      if (doc.selectNodes(xpath).isEmpty()) {
        elemTop=getTopElementWithUser(treeObj.getServerRoot().getUser().getUsername(),UnifyUrl(treeObj.getServerRoot().getWsKey().toString()));
      }
 else {
        if (treeObj.getType() == TreeObject.TRANSFORMER && treeObj.getParent() == null) {
          xpath+="String_Node_Str";
        }
        elemTop=(Element)doc.selectNodes(xpath).get(0);
      }
      String selPath="String_Node_Str" + filterOutBlank(treeObj.getDisplayName()) + "String_Node_Str"+ treeObj.getType()+ "String_Node_Str";
      if (elemTop.selectNodes(selPath).isEmpty()) {
        elemFolder=elemTop.addElement(filterOutBlank(treeObj.getDisplayName()));
        elemFolder.setText(treeObj.getType() + "String_Node_Str");
      }
 else {
        elemFolder=(Element)elemTop.selectNodes(selPath).get(0);
      }
    }
  }
 else {
    elemFolder=(Element)doc.selectNodes(xpath).get(0);
  }
  return elemFolder;
}