Program: 127399
Project: 127399
Buggy source:
private void addParticleDetail(XSDSchema xsdSchema,XSDParticle xsdParticle,ATreeNode parentNode,String currentPath) throws OdaException, IllegalAccessException, InvocationTargetException {
  XSDTerm xsdTerm=xsdParticle.getTerm();
  if (xsdTerm instanceof XSDElementDeclaration) {
    XSDElementDeclaration xsdElementDeclarationParticle=(XSDElementDeclaration)xsdTerm;
    if (particleToTreeNode.containsKey(xsdElementDeclarationParticle)) {
      ATreeNode originalTreeNode=particleToTreeNode.get(xsdElementDeclarationParticle);
      ATreeNode partNode=new ATreeNode();
      partNode.setCurrentNamespace(originalTreeNode.getCurrentNamespace());
      partNode.setValue(originalTreeNode.getValue());
      partNode.setType(ATreeNode.ELEMENT_TYPE);
      partNode.setDataType(originalTreeNode.getDataType());
      partNode.addChild(originalTreeNode.getChildren());
      parentNode.addChild(partNode);
      return;
    }
    ATreeNode partNode=new ATreeNode();
    particleToTreeNode.put(xsdElementDeclarationParticle,partNode);
    String elementName=xsdElementDeclarationParticle.getName();
    String prefix=null;
    String namespace=xsdElementDeclarationParticle.getTargetNamespace();
    XSDTypeDefinition typeDef=xsdElementDeclarationParticle.getTypeDefinition();
    if (typeDef == null) {
      XSDSchema schemaFromNamespace=getXSDSchemaFromNamespace(namespace);
      if (schemaFromNamespace == null) {
        schemaFromNamespace=xsdSchema;
      }
      xsdElementDeclarationParticle=schemaFromNamespace.resolveElementDeclarationURI(xsdElementDeclarationParticle.getURI());
      typeDef=xsdElementDeclarationParticle.getTypeDefinition();
    }
    String typeNamespace=typeDef.getTargetNamespace();
    if (typeNamespace != null && !typeNamespace.equals(namespace)) {
      XSDSchema schemaOfType=getXSDSchemaFromNamespace(typeNamespace);
      if (schemaOfType != null) {
        XSDTypeDefinition typeDefinition=schemaOfType.resolveComplexTypeDefinitionURI(typeDef.getURI());
        if (typeDefinition != null && typeDefinition.getContainer() != null) {
          typeDef=typeDefinition;
        }
      }
    }
    if (namespace != null) {
      prefix=namespaceToPrefix.get(namespace);
      if (prefix == null) {
        prefix=((XSDElementDeclaration)xsdTerm).getQName().contains("String_Node_Str") ? ((XSDElementDeclaration)xsdTerm).getQName().split("String_Node_Str")[0] : "String_Node_Str";
        if (isEnableGeneratePrefix() && (prefix == null || prefix.isEmpty())) {
          prefix="String_Node_Str" + prefixNumberGenerated;
          prefixNumberGenerated++;
        }
        if (namespaceToPrefix.containsValue(prefix)) {
          prefix=prefix + prefixNumberGenerated;
          prefixNumberGenerated++;
        }
        if (prefix != null && !prefix.isEmpty()) {
          namespaceToPrefix.put(namespace,prefix);
        }
 else {
          ATreeNode namespaceNode=new ATreeNode();
          namespaceNode.setDataType("String_Node_Str");
          namespaceNode.setType(ATreeNode.NAMESPACE_TYPE);
          namespaceNode.setValue(namespace);
          partNode.addChild(namespaceNode);
        }
      }
    }
    partNode.setCurrentNamespace(namespace);
    if (prefix != null && !prefix.isEmpty()) {
      elementName=prefix + "String_Node_Str" + elementName;
    }
    partNode.setValue(elementName);
    partNode.setType(ATreeNode.ELEMENT_TYPE);
    partNode.setDataType(xsdElementDeclarationParticle.getName());
    parentNode.addChild(partNode);
    boolean resolvedAsComplex=false;
    if (typeDef instanceof XSDComplexTypeDefinition) {
      if (!currentPath.contains("String_Node_Str" + elementName + "String_Node_Str")) {
        String path=currentPath + elementName + "String_Node_Str";
        XSDTypeDefinition xsdTypeDefinition=typeDef;
        if (xsdTypeDefinition != null && xsdTypeDefinition.getName() != null) {
          partNode.setDataType(xsdTypeDefinition.getQName());
        }
        addComplexTypeDetails(xsdSchema,partNode,xsdTypeDefinition,prefix,namespace,path);
      }
      resolvedAsComplex=true;
    }
 else     if (typeDef.getTargetNamespace() != null) {
      resolvedAsComplex=true;
      if (!currentPath.contains("String_Node_Str" + elementName + "String_Node_Str")) {
        String path=currentPath + elementName + "String_Node_Str";
        XSDComplexTypeDefinition generalType=xsdSchema.resolveComplexTypeDefinition(typeDef.getQName());
        XSDTypeDefinition xsdTypeDefinition=xsdElementDeclarationParticle.getTypeDefinition();
        if (generalType.getContainer() != null) {
          xsdTypeDefinition=generalType;
        }
        if (xsdTypeDefinition != null && xsdTypeDefinition.getName() != null) {
          partNode.setDataType(xsdTypeDefinition.getName());
        }
        if (xsdTypeDefinition instanceof XSDComplexTypeDefinition) {
          addComplexTypeDetails(xsdSchema,partNode,xsdTypeDefinition,prefix,namespace,path);
        }
 else {
          resolvedAsComplex=false;
        }
      }
    }
    if (!resolvedAsComplex) {
      String dataType=xsdElementDeclarationParticle.getTypeDefinition().getQName();
      if (xsdElementDeclarationParticle.getTypeDefinition().getBaseType() != null) {
        if (dataType == null && !"String_Node_Str".equals(xsdElementDeclarationParticle.getTypeDefinition().getBaseType().getQName())) {
          dataType=xsdElementDeclarationParticle.getTypeDefinition().getBaseType().getQName();
        }
      }
      partNode.setDataType(dataType);
    }
    handleOptionalAttribute(partNode,xsdParticle);
    addSubstitutionDetails(xsdSchema,partNode,xsdElementDeclarationParticle,null);
  }
 else   if (xsdTerm instanceof XSDModelGroup) {
    XSDModelGroup xsdModelGroup=(XSDModelGroup)xsdTerm;
    ATreeNode node=addChoiceDetails(parentNode,xsdModelGroup);
    handleOptionalAttribute(node,xsdParticle);
    for (    Object element : xsdModelGroup.getParticles()) {
      XSDParticle childParticle=(XSDParticle)element;
      addParticleDetail(xsdSchema,childParticle,node,currentPath);
    }
  }
}

Fixed version (ground truth):
private void addParticleDetail(XSDSchema xsdSchema,XSDParticle xsdParticle,ATreeNode parentNode,String currentPath) throws OdaException, IllegalAccessException, InvocationTargetException {
  XSDTerm xsdTerm=xsdParticle.getTerm();
  if (xsdTerm instanceof XSDElementDeclaration) {
    XSDElementDeclaration xsdElementDeclarationParticle=(XSDElementDeclaration)xsdTerm;
    if (particleToTreeNode.containsKey(xsdElementDeclarationParticle)) {
      ATreeNode originalTreeNode=particleToTreeNode.get(xsdElementDeclarationParticle);
      ATreeNode partNode=new ATreeNode();
      partNode.setCurrentNamespace(originalTreeNode.getCurrentNamespace());
      partNode.setValue(originalTreeNode.getValue());
      partNode.setType(ATreeNode.ELEMENT_TYPE);
      partNode.setDataType(originalTreeNode.getDataType());
      partNode.addChild(originalTreeNode.getChildren());
      parentNode.addChild(partNode);
      return;
    }
    ATreeNode partNode=new ATreeNode();
    particleToTreeNode.put(xsdElementDeclarationParticle,partNode);
    String elementName=xsdElementDeclarationParticle.getName();
    String prefix=null;
    String namespace=xsdElementDeclarationParticle.getTargetNamespace();
    XSDTypeDefinition typeDef=xsdElementDeclarationParticle.getTypeDefinition();
    if (typeDef == null) {
      XSDSchema schemaFromNamespace=getXSDSchemaFromNamespace(namespace);
      if (schemaFromNamespace == null) {
        schemaFromNamespace=xsdSchema;
      }
      xsdElementDeclarationParticle=schemaFromNamespace.resolveElementDeclarationURI(xsdElementDeclarationParticle.getURI());
      typeDef=xsdElementDeclarationParticle.getTypeDefinition();
    }
    String typeNamespace=typeDef.getTargetNamespace();
    if (typeNamespace != null && !typeNamespace.equals(namespace)) {
      XSDSchema schemaOfType=getXSDSchemaFromNamespace(typeNamespace);
      if (schemaOfType != null) {
        XSDTypeDefinition typeDefinition=schemaOfType.resolveComplexTypeDefinitionURI(typeDef.getURI());
        if (typeDefinition != null && typeDefinition.getContainer() != null) {
          typeDef=typeDefinition;
        }
      }
    }
    if (namespace != null) {
      prefix=namespaceToPrefix.get(namespace);
      if (prefix == null) {
        prefix=((XSDElementDeclaration)xsdTerm).getQName().contains("String_Node_Str") ? ((XSDElementDeclaration)xsdTerm).getQName().split("String_Node_Str")[0] : "String_Node_Str";
        if (isEnableGeneratePrefix() && (prefix == null || prefix.isEmpty())) {
          prefix="String_Node_Str" + prefixNumberGenerated;
          prefixNumberGenerated++;
        }
        if (namespaceToPrefix.containsValue(prefix)) {
          prefix=prefix + prefixNumberGenerated;
          prefixNumberGenerated++;
        }
        if (prefix != null && !prefix.isEmpty()) {
          namespaceToPrefix.put(namespace,prefix);
        }
 else {
          ATreeNode namespaceNode=new ATreeNode();
          namespaceNode.setDataType("String_Node_Str");
          namespaceNode.setType(ATreeNode.NAMESPACE_TYPE);
          namespaceNode.setValue(namespace);
          partNode.addChild(namespaceNode);
        }
      }
    }
    partNode.setCurrentNamespace(namespace);
    if (prefix != null && !prefix.isEmpty()) {
      elementName=prefix + "String_Node_Str" + elementName;
    }
    partNode.setValue(elementName);
    partNode.setType(ATreeNode.ELEMENT_TYPE);
    partNode.setDataType(xsdElementDeclarationParticle.getName());
    parentNode.addChild(partNode);
    boolean resolvedAsComplex=false;
    if (typeDef instanceof XSDComplexTypeDefinition) {
      if (!currentPath.contains("String_Node_Str" + elementName + "String_Node_Str")) {
        String path=currentPath + elementName + "String_Node_Str";
        XSDTypeDefinition xsdTypeDefinition=typeDef;
        if (xsdTypeDefinition != null && xsdTypeDefinition.getName() != null) {
          partNode.setDataType(xsdTypeDefinition.getQName());
        }
        addComplexTypeDetails(xsdSchema,partNode,xsdTypeDefinition,prefix,namespace,path);
      }
      resolvedAsComplex=true;
    }
 else     if (typeDef.getTargetNamespace() != null) {
      resolvedAsComplex=true;
      if (!currentPath.contains("String_Node_Str" + elementName + "String_Node_Str")) {
        String path=currentPath + elementName + "String_Node_Str";
        XSDComplexTypeDefinition generalType=xsdSchema.resolveComplexTypeDefinition(typeDef.getQName());
        XSDTypeDefinition xsdTypeDefinition=xsdElementDeclarationParticle.getTypeDefinition();
        if (generalType.getContainer() != null) {
          xsdTypeDefinition=generalType;
        }
        if (xsdTypeDefinition != null && xsdTypeDefinition.getName() != null) {
          partNode.setDataType(xsdTypeDefinition.getName());
        }
        if (xsdTypeDefinition instanceof XSDComplexTypeDefinition) {
          addComplexTypeDetails(xsdSchema,partNode,xsdTypeDefinition,prefix,namespace,path);
        }
 else {
          resolvedAsComplex=false;
        }
      }
    }
    if (!resolvedAsComplex) {
      String dataType=xsdElementDeclarationParticle.getTypeDefinition().getQName();
      if (!XSDConstants.isSchemaForSchemaNamespace(xsdElementDeclarationParticle.getTypeDefinition().getTargetNamespace()) && xsdElementDeclarationParticle.getTypeDefinition().getBaseType() != null) {
        if (!"String_Node_Str".equals(xsdElementDeclarationParticle.getTypeDefinition().getBaseType().getQName())) {
          dataType=xsdElementDeclarationParticle.getTypeDefinition().getBaseType().getQName();
        }
      }
      partNode.setDataType(dataType);
    }
    handleOptionalAttribute(partNode,xsdParticle);
    addSubstitutionDetails(xsdSchema,partNode,xsdElementDeclarationParticle,null);
  }
 else   if (xsdTerm instanceof XSDModelGroup) {
    XSDModelGroup xsdModelGroup=(XSDModelGroup)xsdTerm;
    ATreeNode node=addChoiceDetails(parentNode,xsdModelGroup);
    handleOptionalAttribute(node,xsdParticle);
    for (    Object element : xsdModelGroup.getParticles()) {
      XSDParticle childParticle=(XSDParticle)element;
      addParticleDetail(xsdSchema,childParticle,node,currentPath);
    }
  }
}