Program: 148979
Project: 148979
Buggy source:
public IStatus doAction(){
  try {
    IStructuredSelection selection=(IStructuredSelection)page.getTreeViewer().getSelection();
    selParticle=(XSDParticle)selection.getFirstElement();
    if (!(selParticle.getContainer() instanceof XSDModelGroup))     return Status.CANCEL_STATUS;
    ;
    XSDModelGroup group=(XSDModelGroup)selParticle.getContainer();
    int index=0;
    int i=0;
    for (Iterator iter=group.getContents().iterator(); iter.hasNext(); ) {
      XSDParticle p=(XSDParticle)iter.next();
      if (p.equals(selParticle)) {
        index=i;
        break;
      }
      i++;
    }
    EList<XSDElementDeclaration> eDecls=schema.getElementDeclarations();
    ArrayList<String> elementDeclarations=new ArrayList<String>();
    for (Iterator iter=eDecls.iterator(); iter.hasNext(); ) {
      XSDElementDeclaration d=(XSDElementDeclaration)iter.next();
      elementDeclarations.add(d.getQName() + (d.getTargetNamespace() != null ? "String_Node_Str" + d.getTargetNamespace() : "String_Node_Str"));
    }
    elementDeclarations.add("String_Node_Str");
    dialog=new BusinessElementInputDialog(this,page.getSite().getShell(),"String_Node_Str",null,null,elementDeclarations,0,1);
    dialog.setBlockOnOpen(true);
    int ret=dialog.open();
    if (ret == Dialog.CANCEL) {
      return Status.CANCEL_STATUS;
    }
    XSDFactory factory=XSDSchemaBuildingTools.getXSDFactory();
    XSDElementDeclaration decl=factory.createXSDElementDeclaration();
    decl.setName(this.elementName);
    if (!refName.equals("String_Node_Str")) {
      XSDElementDeclaration ref=Util.findReference(refName,schema);
      if (ref != null) {
        decl.setResolvedElementDeclaration(ref);
      }
    }
 else {
      decl.setTypeDefinition(schema.resolveSimpleTypeDefinition(schema.getSchemaForSchemaNamespace(),"String_Node_Str"));
    }
    XSDParticle particle=factory.createXSDParticle();
    particle.setContent(decl);
    particle.setMinOccurs(this.minOccurs);
    particle.setMaxOccurs(this.maxOccurs);
    group.getContents().add(group.getContents().size(),particle);
    group.updateElement();
    page.refresh();
    page.getTreeViewer().setSelection(new StructuredSelection(particle),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();
    selParticle=(XSDParticle)selection.getFirstElement();
    if (!(selParticle.getContainer() instanceof XSDModelGroup))     return Status.CANCEL_STATUS;
    ;
    XSDModelGroup group=(XSDModelGroup)selParticle.getContainer();
    int index=0;
    int i=0;
    for (Iterator iter=group.getContents().iterator(); iter.hasNext(); ) {
      XSDParticle p=(XSDParticle)iter.next();
      if (p.equals(selParticle)) {
        index=i;
        break;
      }
      i++;
    }
    EList<XSDElementDeclaration> eDecls=schema.getElementDeclarations();
    ArrayList<String> elementDeclarations=new ArrayList<String>();
    for (Iterator iter=eDecls.iterator(); iter.hasNext(); ) {
      XSDElementDeclaration d=(XSDElementDeclaration)iter.next();
      elementDeclarations.add(d.getQName() + (d.getTargetNamespace() != null ? "String_Node_Str" + d.getTargetNamespace() : "String_Node_Str"));
    }
    elementDeclarations.add("String_Node_Str");
    dialog=new BusinessElementInputDialog(this,page.getSite().getShell(),"String_Node_Str",null,null,elementDeclarations,0,1,true);
    dialog.setBlockOnOpen(true);
    int ret=dialog.open();
    if (ret == Dialog.CANCEL) {
      return Status.CANCEL_STATUS;
    }
    XSDFactory factory=XSDSchemaBuildingTools.getXSDFactory();
    XSDElementDeclaration decl=factory.createXSDElementDeclaration();
    decl.setName(this.elementName);
    if (!refName.equals("String_Node_Str")) {
      XSDElementDeclaration ref=Util.findReference(refName,schema);
      if (ref != null) {
        decl.setResolvedElementDeclaration(ref);
      }
    }
 else {
      decl.setTypeDefinition(schema.resolveSimpleTypeDefinition(schema.getSchemaForSchemaNamespace(),"String_Node_Str"));
    }
    XSDParticle particle=factory.createXSDParticle();
    particle.setContent(decl);
    particle.setMinOccurs(this.minOccurs);
    particle.setMaxOccurs(this.maxOccurs);
    group.getContents().add(group.getContents().size(),particle);
    group.updateElement();
    if (dialog.isInherit()) {
      XSDTerm totm=particle.getTerm();
      XSDElementDeclaration concept=(XSDElementDeclaration)Util.getParent(selParticle);
      XSDAnnotation fromannotation=null;
      if (concept != null)       fromannotation=concept.getAnnotation();
      if (fromannotation != null) {
        XSDAnnotationsStructure struc=new XSDAnnotationsStructure(totm);
        if (((XSDElementDeclaration)totm).getType() != null) {
          addAnnotion(struc,fromannotation);
        }
      }
    }
    page.refresh();
    page.getTreeViewer().setSelection(new StructuredSelection(particle),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;
}