Program: 148727
Project: 148727
Buggy source:
public IStatus doAction(){
  try {
    IStructuredSelection selection=(IStructuredSelection)page.getTreeViewer().getSelection();
    XSDXPathDefinition xpath=(XSDXPathDefinition)selection.getFirstElement();
    icd=(XSDIdentityConstraintDefinition)xpath.getContainer();
    List<String> childNames=Util.getChildElementNames((XSDElementDeclaration)icd.getContainer());
    SelectFieldDialog id=new SelectFieldDialog(page.getSite().getShell(),"String_Node_Str",childNames,xpath.getValue());
    id.create();
    id.setBlockOnOpen(true);
    int ret=id.open();
    if (ret == Window.CANCEL) {
      return Status.CANCEL_STATUS;
    }
    String field=id.getField();
    if (field.length() == 0)     return Status.CANCEL_STATUS;
    XSDXPathDefinition newXpath=XSDSchemaBuildingTools.getXSDFactory().createXSDXPathDefinition();
    newXpath.setValue(field);
    if (xpath.getVariety().equals(XSDXPathVariety.FIELD_LITERAL)) {
      int index=icd.getFields().indexOf(xpath);
      newXpath.setVariety(XSDXPathVariety.FIELD_LITERAL);
      icd.getFields().set(index,newXpath);
    }
 else {
      newXpath.setVariety(XSDXPathVariety.SELECTOR_LITERAL);
      icd.setSelector(newXpath);
    }
    icd.updateElement();
    page.refresh();
    page.getTreeViewer().setSelection(new StructuredSelection(newXpath),true);
    page.markDirty();
  }
 catch (  Exception e) {
    e.printStackTrace();
    MessageDialog.openError(page.getSite().getShell(),"String_Node_Str","String_Node_Str" + e.getLocalizedMessage());
    return Status.CANCEL_STATUS;
  }
  return Status.OK_STATUS;
}

Fixed version (ground truth):
public IStatus doAction(){
  try {
    IStructuredSelection selection=(IStructuredSelection)page.getTreeViewer().getSelection();
    XSDXPathDefinition xpath=(XSDXPathDefinition)selection.getFirstElement();
    icd=(XSDIdentityConstraintDefinition)xpath.getContainer();
    List<String> childNames=Util.getChildElementNames("String_Node_Str",(XSDElementDeclaration)icd.getContainer());
    SelectFieldDialog id=new SelectFieldDialog(page.getSite().getShell(),"String_Node_Str",childNames,xpath.getValue());
    id.create();
    id.setBlockOnOpen(true);
    int ret=id.open();
    if (ret == Window.CANCEL) {
      return Status.CANCEL_STATUS;
    }
    String field=id.getField();
    if (field.length() == 0)     return Status.CANCEL_STATUS;
    XSDXPathDefinition newXpath=XSDSchemaBuildingTools.getXSDFactory().createXSDXPathDefinition();
    newXpath.setValue(field);
    if (xpath.getVariety().equals(XSDXPathVariety.FIELD_LITERAL)) {
      int index=icd.getFields().indexOf(xpath);
      newXpath.setVariety(XSDXPathVariety.FIELD_LITERAL);
      icd.getFields().set(index,newXpath);
    }
 else {
      newXpath.setVariety(XSDXPathVariety.SELECTOR_LITERAL);
      icd.setSelector(newXpath);
    }
    icd.updateElement();
    page.refresh();
    page.getTreeViewer().setSelection(new StructuredSelection(newXpath),true);
    page.markDirty();
  }
 catch (  Exception e) {
    e.printStackTrace();
    MessageDialog.openError(page.getSite().getShell(),"String_Node_Str","String_Node_Str" + e.getLocalizedMessage());
    return Status.CANCEL_STATUS;
  }
  return Status.OK_STATUS;
}