Program: 148827
Project: 148827
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,true);
    dialog.setBlockOnOpen(true);
    int ret=dialog.open();
    if (ret == Dialog.CANCEL) {
      return Status.CANCEL_STATUS;
    }
    XSDElementDeclaration elem=(XSDElementDeclaration)selParticle.getContent();
    if (Util.changeElementTypeToSequence(elem,maxOccurs) == Status.CANCEL_STATUS) {
      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);
    if (maxOccurs > -1) {
      particle.setMaxOccurs(this.maxOccurs);
    }
 else {
      particle.setMaxOccurs(this.maxOccurs);
      group.getContents().add(group.getContents().size(),particle);
      group.updateElement();
      if (particle.getElement().getAttributeNode("String_Node_Str") != null)       particle.getElement().getAttributeNode("String_Node_Str").setNodeValue("String_Node_Str");
 else {
        particle.getElement().setAttribute("String_Node_Str","String_Node_Str");
      }
    }
    if (maxOccurs > -1) {
      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;
}

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;
    }
    XSDElementDeclaration elem=(XSDElementDeclaration)selParticle.getContent();
    if (Util.changeElementTypeToSequence(elem,maxOccurs) == Status.CANCEL_STATUS) {
      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);
    if (maxOccurs > -1) {
      particle.setMaxOccurs(this.maxOccurs);
    }
 else {
      particle.setMaxOccurs(this.maxOccurs);
      group.getContents().add(group.getContents().size(),particle);
      group.updateElement();
      if (particle.getElement().getAttributeNode("String_Node_Str") != null)       particle.getElement().getAttributeNode("String_Node_Str").setNodeValue("String_Node_Str");
 else {
        particle.getElement().setAttribute("String_Node_Str","String_Node_Str");
      }
    }
    if (maxOccurs > -1) {
      group.getContents().add(group.getContents().size(),particle);
      group.updateElement();
    }
    if (dialog.isInherit()) {
      XSDTerm totm=particle.getTerm();
      XSDElementDeclaration concept=null;
      if (Util.getParent(selParticle) instanceof XSDElementDeclaration)       concept=(XSDElementDeclaration)Util.getParent(selParticle);
 else       if (Util.getParent(selParticle) instanceof XSDComplexTypeDefinition) {
        if (selParticle instanceof XSDParticle)         concept=(XSDElementDeclaration)((XSDParticle)selParticle).getContent();
 else         if (selParticle instanceof XSDElementDeclaration)         concept=(XSDElementDeclaration)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;
}