Program: 149051
Project: 149051
Buggy source:
public IStatus doAction(){
  try {
    IStructuredSelection selection=(TreeSelection)page.getTreeViewer().getSelection();
    XSDComponent xSDCom=null;
    if (selection.getFirstElement() instanceof XSDAnnotation)     xSDCom=(XSDAnnotation)selection.getFirstElement();
 else {
      TreePath tPath=((TreeSelection)selection).getPaths()[0];
      for (int i=0; i < tPath.getSegmentCount(); i++) {
        if (tPath.getSegment(i) instanceof XSDAnnotation)         xSDCom=(XSDAnnotation)(tPath.getSegment(i));
      }
    }
    XSDAnnotationsStructure struc=new XSDAnnotationsStructure(xSDCom);
    if (struc.getAnnotation() == null) {
      throw new RuntimeException("String_Node_Str" + xSDCom.getClass().getName());
    }
    sxid=new SimpleXpathInputDialog(page,"String_Node_Str","String_Node_Str",struc.getForeignKey(),new SelectionListener(){
      public void widgetDefaultSelected(      SelectionEvent e){
      }
      public void widgetSelected(      SelectionEvent e){
        sxid.close();
      }
    }
,dataModelName);
    sxid.setBlockOnOpen(true);
    int ret=sxid.open();
    if (ret == Window.CANCEL) {
      return Status.CANCEL_STATUS;
    }
    struc.setForeignKey("String_Node_Str".equals(sxid.getXpath()) ? null : sxid.getXpath().replaceAll("String_Node_Str","String_Node_Str"));
    if (struc.hasChanged()) {
      page.refresh();
      page.getTreeViewer().expandToLevel(xSDCom,2);
      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=(TreeSelection)page.getTreeViewer().getSelection();
    XSDComponent xSDCom=null;
    if (selection.getFirstElement() instanceof Element) {
      TreePath tPath=((TreeSelection)selection).getPaths()[0];
      for (int i=0; i < tPath.getSegmentCount(); i++) {
        if (tPath.getSegment(i) instanceof XSDAnnotation)         xSDCom=(XSDAnnotation)(tPath.getSegment(i));
      }
    }
 else     xSDCom=(XSDComponent)selection.getFirstElement();
    XSDAnnotationsStructure struc=null;
    if (xSDCom != null)     struc=new XSDAnnotationsStructure(xSDCom);
    if (struc == null || struc.getAnnotation() == null) {
      throw new RuntimeException("String_Node_Str" + xSDCom.getClass().getName());
    }
    sxid=new SimpleXpathInputDialog(page,"String_Node_Str","String_Node_Str",struc.getForeignKey(),new SelectionListener(){
      public void widgetDefaultSelected(      SelectionEvent e){
      }
      public void widgetSelected(      SelectionEvent e){
        sxid.close();
      }
    }
,dataModelName);
    sxid.setBlockOnOpen(true);
    int ret=sxid.open();
    if (ret == Window.CANCEL) {
      return Status.CANCEL_STATUS;
    }
    struc.setForeignKey("String_Node_Str".equals(sxid.getXpath()) ? null : sxid.getXpath().replaceAll("String_Node_Str","String_Node_Str"));
    if (struc.hasChanged()) {
      page.refresh();
      page.getTreeViewer().expandToLevel(xSDCom,2);
      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;
}