Program: 148728
Project: 148728
Buggy source:
public IStatus doAction(){
  try {
    int index=-1;
    IStructuredSelection selection=(IStructuredSelection)page.getTreeViewer().getSelection();
    List<String> childNames=new ArrayList<String>();
    if (selection.getFirstElement() instanceof XSDElementDeclaration) {
      decl=(XSDElementDeclaration)selection.getFirstElement();
    }
 else     if (selection.getFirstElement() instanceof XSDIdentityConstraintDefinition) {
      XSDIdentityConstraintDefinition selIcd=(XSDIdentityConstraintDefinition)selection.getFirstElement();
      decl=(XSDElementDeclaration)(selIcd.getContainer());
      int i=0;
      for (Iterator iter=decl.getIdentityConstraintDefinitions().iterator(); iter.hasNext(); ) {
        XSDIdentityConstraintDefinition ic=(XSDIdentityConstraintDefinition)iter.next();
        if (ic.equals(selIcd)) {
          index=i;
          break;
        }
        i++;
      }
    }
 else     if (selection.getFirstElement() instanceof XSDParticle) {
      XSDParticle selParticle=(XSDParticle)selection.getFirstElement();
      if (!(selParticle.getTerm() instanceof XSDElementDeclaration))       return Status.CANCEL_STATUS;
      decl=(XSDElementDeclaration)selParticle.getTerm();
    }
 else {
      MessageDialog.openError(this.page.getSite().getShell(),"String_Node_Str","String_Node_Str" + selection.getFirstElement().getClass().getName());
      return Status.CANCEL_STATUS;
    }
    childNames=Util.getChildElementNames(decl);
    dialog=new IdentityConstraintInputDialog(this,page.getSite().getShell(),"String_Node_Str",childNames,decl.getName());
    dialog.setBlockOnOpen(true);
    int ret=dialog.open();
    if (ret == Window.CANCEL) {
      return Status.CANCEL_STATUS;
    }
    XSDFactory factory=XSDSchemaBuildingTools.getXSDFactory();
    XSDIdentityConstraintDefinition icd=factory.createXSDIdentityConstraintDefinition();
    icd.setName(keyName);
    icd.setIdentityConstraintCategory(type);
    XSDXPathDefinition selector=factory.createXSDXPathDefinition();
    selector.setVariety(XSDXPathVariety.SELECTOR_LITERAL);
    selector.setValue("String_Node_Str");
    icd.setSelector(selector);
    XSDXPathDefinition field=factory.createXSDXPathDefinition();
    field.setVariety(XSDXPathVariety.FIELD_LITERAL);
    field.setValue("String_Node_Str");
    if (fieldName == null || fieldName.trim().length() == 0) {
      if (decl.getTypeDefinition() instanceof XSDComplexTypeDefinition) {
        XSDComplexTypeContent ctc=((XSDComplexTypeDefinition)decl.getTypeDefinition()).getContent();
        if (ctc instanceof XSDParticle) {
          if (((XSDParticle)ctc).getTerm() instanceof XSDModelGroup) {
            XSDModelGroup mg=(XSDModelGroup)((XSDParticle)ctc).getTerm();
            if (mg.getContents().size() > 0)             if (((XSDParticle)mg.getContents().get(0)).getTerm() instanceof XSDElementDeclaration)             field.setValue(((XSDElementDeclaration)(((XSDParticle)mg.getContents().get(0)).getTerm())).getName());
          }
        }
      }
    }
 else {
      field.setValue(fieldName);
    }
    icd.getFields().add(field);
    decl.getIdentityConstraintDefinitions().add(index + 1,icd);
    decl.updateElement();
    page.refresh();
    page.getTreeViewer().setSelection(new StructuredSelection(icd),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 {
    int index=-1;
    IStructuredSelection selection=(IStructuredSelection)page.getTreeViewer().getSelection();
    List<String> childNames=new ArrayList<String>();
    if (selection.getFirstElement() instanceof XSDElementDeclaration) {
      decl=(XSDElementDeclaration)selection.getFirstElement();
    }
 else     if (selection.getFirstElement() instanceof XSDIdentityConstraintDefinition) {
      XSDIdentityConstraintDefinition selIcd=(XSDIdentityConstraintDefinition)selection.getFirstElement();
      decl=(XSDElementDeclaration)(selIcd.getContainer());
      int i=0;
      for (Iterator iter=decl.getIdentityConstraintDefinitions().iterator(); iter.hasNext(); ) {
        XSDIdentityConstraintDefinition ic=(XSDIdentityConstraintDefinition)iter.next();
        if (ic.equals(selIcd)) {
          index=i;
          break;
        }
        i++;
      }
    }
 else     if (selection.getFirstElement() instanceof XSDParticle) {
      XSDParticle selParticle=(XSDParticle)selection.getFirstElement();
      if (!(selParticle.getTerm() instanceof XSDElementDeclaration))       return Status.CANCEL_STATUS;
      decl=(XSDElementDeclaration)selParticle.getTerm();
    }
 else {
      MessageDialog.openError(this.page.getSite().getShell(),"String_Node_Str","String_Node_Str" + selection.getFirstElement().getClass().getName());
      return Status.CANCEL_STATUS;
    }
    childNames=Util.getChildElementNames("String_Node_Str",decl);
    dialog=new IdentityConstraintInputDialog(this,page.getSite().getShell(),"String_Node_Str",childNames,decl.getName());
    dialog.setBlockOnOpen(true);
    int ret=dialog.open();
    if (ret == Window.CANCEL) {
      return Status.CANCEL_STATUS;
    }
    XSDFactory factory=XSDSchemaBuildingTools.getXSDFactory();
    XSDIdentityConstraintDefinition icd=factory.createXSDIdentityConstraintDefinition();
    icd.setName(keyName);
    icd.setIdentityConstraintCategory(type);
    XSDXPathDefinition selector=factory.createXSDXPathDefinition();
    selector.setVariety(XSDXPathVariety.SELECTOR_LITERAL);
    selector.setValue("String_Node_Str");
    icd.setSelector(selector);
    XSDXPathDefinition field=factory.createXSDXPathDefinition();
    field.setVariety(XSDXPathVariety.FIELD_LITERAL);
    field.setValue("String_Node_Str");
    if (fieldName == null || fieldName.trim().length() == 0) {
      if (decl.getTypeDefinition() instanceof XSDComplexTypeDefinition) {
        XSDComplexTypeContent ctc=((XSDComplexTypeDefinition)decl.getTypeDefinition()).getContent();
        if (ctc instanceof XSDParticle) {
          if (((XSDParticle)ctc).getTerm() instanceof XSDModelGroup) {
            XSDModelGroup mg=(XSDModelGroup)((XSDParticle)ctc).getTerm();
            if (mg.getContents().size() > 0)             if (((XSDParticle)mg.getContents().get(0)).getTerm() instanceof XSDElementDeclaration)             field.setValue(((XSDElementDeclaration)(((XSDParticle)mg.getContents().get(0)).getTerm())).getName());
          }
        }
      }
    }
 else {
      field.setValue(fieldName);
    }
    icd.getFields().add(field);
    decl.getIdentityConstraintDefinitions().add(index + 1,icd);
    decl.updateElement();
    page.refresh();
    page.getTreeViewer().setSelection(new StructuredSelection(icd),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;
}