Program: 125536
Project: 125536
Buggy source:
/** 
 * DOC wchen Comment method "createMetadataFromXSD".
 * @param parameter
 * @param connectionLabel
 * @param portTypeName
 * @param operationName
 * @param schemaFile
 * @param selectItems
 * @param fileForInnerContent
 * @param populationUtil
 * @throws IOException
 */
public static void createMetadataFromXSD(QName parameter,String connectionLabel,String portTypeName,String operationName,Collection<XmlFileConnectionItem> selectItems,File fileForInnerContent,XSDPopulationUtil2 populationUtil) throws IOException {
  String targetNameSpace=parameter.getNamespaceURI();
  XSDSchema xsdSchema=populationUtil.getXSDSchemaFromNamespace(targetNameSpace);
  if (xsdSchema == null) {
    return;
  }
  String name=parameter.getLocalPart();
  XmlFileConnection connection=null;
  Property connectionProperty=null;
  XmlFileConnectionItem connectionItem=null;
  String oldConnectionId=null;
  String oldTableId=null;
  IMetadataTable oldMetadataTable=null;
  Map<String,String> oldTableMap=null;
  if (!selectItems.isEmpty()) {
    boolean needRewrite=false;
    for (    XmlFileConnectionItem item : selectItems) {
      connectionProperty=item.getProperty();
      if (connectionProperty.getLabel().equals(name)) {
        oldConnectionId=connectionProperty.getId();
        connectionItem=item;
        connection=(XmlFileConnection)connectionItem.getConnection();
        needRewrite=true;
        Set<MetadataTable> tables=ConnectionHelper.getTables(connection);
        MetadataTable oldTable=null;
        if (tables.size() > 0) {
          oldTable=tables.toArray(new MetadataTable[0])[0];
          oldTableId=oldTable.getId();
          oldMetadataTable=ConvertionHelper.convert(oldTable);
        }
        oldTableMap=RepositoryUpdateManager.getOldTableIdAndNameMap(connectionItem,oldTable,false);
        break;
      }
    }
    if (!needRewrite && !isNameValidInXmlFileConnection(parameter,portTypeName,operationName)) {
      return;
    }
  }
  connection=ConnectionFactory.eINSTANCE.createXmlFileConnection();
  connection.setName(ERepositoryObjectType.METADATA_FILE_XML.getKey());
  connectionItem=PropertiesFactory.eINSTANCE.createXmlFileConnectionItem();
  connectionProperty=PropertiesFactory.eINSTANCE.createProperty();
  connectionProperty.setAuthor(((RepositoryContext)CoreRuntimePlugin.getInstance().getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY)).getUser());
  connectionProperty.setLabel(connectionLabel);
  connectionProperty.setVersion(VersionUtils.DEFAULT_VERSION);
  connectionProperty.setStatusCode("String_Node_Str");
  connectionItem.setProperty(connectionProperty);
  connectionItem.setConnection(connection);
  connection.setInputModel(false);
  ByteArray byteArray=PropertiesFactory.eINSTANCE.createByteArray();
  byteArray.setInnerContentFromFile(fileForInnerContent);
  connection.setFileContent(byteArray.getInnerContent());
  connection.setXmlFilePath(fileForInnerContent.getName());
  connection.setTargetNameSpace(targetNameSpace);
  try {
    List<ATreeNode> rootNodes=populationUtil.getAllRootNodes(xsdSchema);
    ATreeNode node=null;
    for (    ATreeNode curNode : rootNodes) {
      String curName=(String)curNode.getValue();
      if (curName.contains("String_Node_Str")) {
        if (curName.split("String_Node_Str")[1].equals(name)) {
          node=curNode;
          break;
        }
      }
 else       if (curName.equals(name)) {
        node=curNode;
        break;
      }
    }
    node=populationUtil.getSchemaTree(xsdSchema,node);
    orderId=1;
    loopElementFound=false;
    if (ConnectionHelper.getTables(connection).isEmpty()) {
      MetadataTable table=ConnectionFactory.eINSTANCE.createMetadataTable();
      if (oldTableId != null) {
        table.setId(oldTableId);
      }
 else {
        table.setId(ProxyRepositoryFactory.getInstance().getNextId());
      }
      RecordFile record=(RecordFile)ConnectionHelper.getPackage(connection.getName(),connection,RecordFile.class);
      if (record != null) {
        PackageHelper.addMetadataTable(table,record);
      }
 else {
        RecordFile newrecord=RecordFactory.eINSTANCE.createRecordFile();
        newrecord.setName(connection.getName());
        ConnectionHelper.addPackage(newrecord,connection);
        PackageHelper.addMetadataTable(table,newrecord);
      }
    }
    boolean haveElement=false;
    for (    Object curNode : node.getChildren()) {
      if (((ATreeNode)curNode).getType() == ATreeNode.ELEMENT_TYPE) {
        haveElement=true;
        break;
      }
    }
    fillRootInfo(connection,node,"String_Node_Str",!haveElement);
  }
 catch (  OdaException e) {
    ExceptionHandler.process(e);
  }
  IProxyRepositoryFactory factory=ProxyRepositoryFactory.getInstance();
  connectionProperty.setId(factory.getNextId());
  try {
    String folderPath=getImportedXmlSchemaPath(targetNameSpace,portTypeName,operationName);
    IPath path=new Path(folderPath);
    factory.create(connectionItem,path,true);
    if (oldConnectionId != null) {
      connectionItem.getProperty().setId(oldConnectionId);
      factory.save(connectionItem);
    }
    propagateSchemaChange(oldMetadataTable,oldTableMap,connection,connectionItem);
    ProxyRepositoryFactory.getInstance().saveProject(ProjectManager.getInstance().getCurrentProject());
  }
 catch (  PersistenceException e) {
    ExceptionHandler.process(e);
  }
catch (  URISyntaxException e) {
    ExceptionHandler.process(e);
  }
}

Fixed version (ground truth):
/** 
 * DOC wchen Comment method "createMetadataFromXSD".
 * @param parameter
 * @param connectionLabel
 * @param portTypeName
 * @param operationName
 * @param schemaFile
 * @param selectItems
 * @param fileForInnerContent
 * @param populationUtil
 * @throws IOException
 * @throws URISyntaxException
 */
public static void createMetadataFromXSD(QName parameter,String connectionLabel,String portTypeName,String operationName,Collection<XmlFileConnectionItem> selectItems,File fileForInnerContent,XSDPopulationUtil2 populationUtil) throws IOException {
  String targetNameSpace=parameter.getNamespaceURI();
  String name=parameter.getLocalPart();
  XmlFileConnection connection=null;
  Property connectionProperty=null;
  XmlFileConnectionItem connectionItem=null;
  String oldConnectionId=null;
  String oldTableId=null;
  IMetadataTable oldMetadataTable=null;
  Map<String,String> oldTableMap=null;
  if (!selectItems.isEmpty()) {
    boolean needRewrite=false;
    for (    XmlFileConnectionItem item : selectItems) {
      connectionProperty=item.getProperty();
      if (connectionProperty.getLabel().equals(name)) {
        oldConnectionId=connectionProperty.getId();
        connectionItem=item;
        connection=(XmlFileConnection)connectionItem.getConnection();
        needRewrite=true;
        Set<MetadataTable> tables=ConnectionHelper.getTables(connection);
        MetadataTable oldTable=null;
        if (tables.size() > 0) {
          oldTable=tables.toArray(new MetadataTable[0])[0];
          oldTableId=oldTable.getId();
          oldMetadataTable=ConvertionHelper.convert(oldTable);
        }
        oldTableMap=RepositoryUpdateManager.getOldTableIdAndNameMap(connectionItem,oldTable,false);
        break;
      }
    }
    if (!needRewrite && !isNameValidInXmlFileConnection(parameter,portTypeName,operationName)) {
      return;
    }
  }
  connection=ConnectionFactory.eINSTANCE.createXmlFileConnection();
  connection.setName(ERepositoryObjectType.METADATA_FILE_XML.getKey());
  connectionItem=PropertiesFactory.eINSTANCE.createXmlFileConnectionItem();
  connectionProperty=PropertiesFactory.eINSTANCE.createProperty();
  connectionProperty.setAuthor(((RepositoryContext)CoreRuntimePlugin.getInstance().getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY)).getUser());
  connectionProperty.setLabel(connectionLabel);
  connectionProperty.setVersion(VersionUtils.DEFAULT_VERSION);
  connectionProperty.setStatusCode("String_Node_Str");
  connectionItem.setProperty(connectionProperty);
  connectionItem.setConnection(connection);
  connection.setInputModel(false);
  ByteArray byteArray=PropertiesFactory.eINSTANCE.createByteArray();
  byteArray.setInnerContentFromFile(fileForInnerContent);
  connection.setFileContent(byteArray.getInnerContent());
  connection.setXmlFilePath(fileForInnerContent.getName());
  connection.setTargetNameSpace(targetNameSpace);
  try {
    XSDSchema xsdSchema=null;
    if (XmlUtil.isWSDLFile(fileForInnerContent.getName())) {
      xsdSchema=populationUtil.getXSDSchemaFromNamespace(targetNameSpace);
    }
 else {
      xsdSchema=populationUtil.getXSDSchema(fileForInnerContent.getAbsolutePath());
    }
    if (xsdSchema == null) {
      return;
    }
    List<ATreeNode> rootNodes=populationUtil.getAllRootNodes(xsdSchema);
    ATreeNode node=null;
    for (    ATreeNode curNode : rootNodes) {
      String curName=(String)curNode.getValue();
      if (curName.contains("String_Node_Str")) {
        if (curName.split("String_Node_Str")[1].equals(name)) {
          node=curNode;
          break;
        }
      }
 else       if (curName.equals(name)) {
        node=curNode;
        break;
      }
    }
    node=populationUtil.getSchemaTree(xsdSchema,node);
    orderId=1;
    loopElementFound=false;
    if (ConnectionHelper.getTables(connection).isEmpty()) {
      MetadataTable table=ConnectionFactory.eINSTANCE.createMetadataTable();
      if (oldTableId != null) {
        table.setId(oldTableId);
      }
 else {
        table.setId(ProxyRepositoryFactory.getInstance().getNextId());
      }
      RecordFile record=(RecordFile)ConnectionHelper.getPackage(connection.getName(),connection,RecordFile.class);
      if (record != null) {
        PackageHelper.addMetadataTable(table,record);
      }
 else {
        RecordFile newrecord=RecordFactory.eINSTANCE.createRecordFile();
        newrecord.setName(connection.getName());
        ConnectionHelper.addPackage(newrecord,connection);
        PackageHelper.addMetadataTable(table,newrecord);
      }
    }
    boolean haveElement=false;
    for (    Object curNode : node.getChildren()) {
      if (((ATreeNode)curNode).getType() == ATreeNode.ELEMENT_TYPE) {
        haveElement=true;
        break;
      }
    }
    fillRootInfo(connection,node,"String_Node_Str",!haveElement);
  }
 catch (  OdaException e) {
    ExceptionHandler.process(e);
  }
catch (  URISyntaxException e1) {
    ExceptionHandler.process(e1);
  }
  IProxyRepositoryFactory factory=ProxyRepositoryFactory.getInstance();
  connectionProperty.setId(factory.getNextId());
  try {
    String folderPath=getImportedXmlSchemaPath(targetNameSpace,portTypeName,operationName);
    IPath path=new Path(folderPath);
    factory.create(connectionItem,path,true);
    if (oldConnectionId != null) {
      connectionItem.getProperty().setId(oldConnectionId);
      factory.save(connectionItem);
    }
    propagateSchemaChange(oldMetadataTable,oldTableMap,connection,connectionItem);
    ProxyRepositoryFactory.getInstance().saveProject(ProjectManager.getInstance().getCurrentProject());
  }
 catch (  PersistenceException e) {
    ExceptionHandler.process(e);
  }
catch (  URISyntaxException e) {
    ExceptionHandler.process(e);
  }
}