Program: 11743
Project: 11743
Buggy source:
@Override protected Diagnostic doExport(Monitor monitor,ModelExporter.ExportData exportData) throws Exception {
  for (  Map.Entry<GenPackage,URI> entry : exportData.genPackageToArtifactURI.entrySet()) {
    GenPackage genPackage=entry.getKey();
    URI xcoreLocationURI=entry.getValue();
    IFile xcoreFile=ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(xcoreLocationURI.toPlatformString(true)));
    final IProject xcoreProject=xcoreFile.getProject();
    if (xcoreProject.isAccessible()) {
      if (!xcoreProject.hasNature(XtextProjectHelper.NATURE_ID)) {
        IProjectDescription description=xcoreProject.getDescription();
        String[] natures=description.getNatureIds();
        String[] newNatures=new String[natures.length + 1];
        System.arraycopy(natures,0,newNatures,0,natures.length);
        newNatures[natures.length]=XtextProjectHelper.NATURE_ID;
        description.setNatureIds(newNatures);
        xcoreProject.setDescription(description,null);
      }
    }
    ResourceSet resourceSet=new ResourceSetImpl();
    resourceSet.getURIConverter().getURIMap().putAll(EcorePlugin.computePlatformURIMap());
    GenModel inputGenModel=(GenModel)resourceSet.getEObject(EcoreUtil.getURI(getGenModel()),true);
    inputGenModel.reconcile();
    Resource inputResource=inputGenModel.eResource();
    Resource outputResource=resourceSet.createResource(xcoreLocationURI);
    GenModel genModel=GenModelFactory.eINSTANCE.createGenModel();
    List<EPackage> ePackageClones=new ArrayList<EPackage>();
    for (    GenPackage inputGenPackage : inputGenModel.getGenPackages()) {
      ePackageClones.add(inputGenPackage.getEcorePackage());
    }
    genModel.initialize(ePackageClones);
    inputResource.getContents().add(genModel);
    genModelInitializer.initialize(genModel,true);
    final GenPackage inputGenPackage=(GenPackage)resourceSet.getEObject(EcoreUtil.getURI(genPackage),true);
    new Object(){
      void visit(      GenBase genBase1,      GenBase genBase2){
        if (genBase1.eClass() == genBase2.eClass()) {
          for (          EAttribute eAttribute : genBase1.eClass().getEAllAttributes()) {
            if (!eAttribute.isMany() && genBase1.eIsSet(eAttribute)) {
              Object value1=genBase1.eGet(eAttribute);
              Object value2=genBase2.eGet(eAttribute);
              if (value1 == null ? value2 != null : !value1.equals(value2)) {
                EModelElement eModelElement=genBase2.getEcoreModelElement();
                if (eModelElement == null && genBase2 instanceof GenModel) {
                  eModelElement=inputGenPackage.getEcorePackage();
                }
                EcoreUtil.setAnnotation(eModelElement,GenModelPackage.eNS_URI,eAttribute.getName(),EcoreUtil.convertToString(eAttribute.getEAttributeType(),value1));
              }
              for (Iterator<EObject> i=genBase1.eContents().iterator(), j=genBase2.eContents().iterator(); i.hasNext() && j.hasNext(); ) {
                EObject content1=i.next();
                EObject content2=j.next();
                if (content1 instanceof GenBase && content2 instanceof GenBase) {
                  visit((GenBase)content1,(GenBase)content2);
                }
              }
            }
          }
        }
      }
    }
.visit(inputGenModel,genModel);
    EcoreXcoreBuilder ecoreXcoreBuilder=ecoreXcoreBuilderProvider.get();
    ecoreXcoreBuilder.initialize(inputGenModel);
    XPackage xPackage=ecoreXcoreBuilder.getXPackage(inputGenPackage.getEcorePackage());
    outputResource.getContents().add(xPackage);
    outputResource.getContents().add(inputGenModel);
    outputResource.getContents().add(inputGenPackage.getEcorePackage());
    GenPackage ecoreGenPackage=inputGenModel.getEcoreGenPackage();
    if (ecoreGenPackage != null) {
      Resource ecoreResource=resourceSet.createResource(URI.createURI("String_Node_Str"));
      ecoreResource.getContents().add(ecoreGenPackage.getGenModel());
    }
    GenPackage xmlTypeGenPackage=inputGenModel.getXMLTypeGenPackage();
    if (xmlTypeGenPackage != null) {
      Resource xmlTypeResource=resourceSet.createResource(URI.createURI("String_Node_Str"));
      xmlTypeResource.getContents().add(xmlTypeGenPackage.getGenModel());
    }
    GenPackage xmlNamespaceGenPackage=inputGenModel.getXMLNamespaceGenPackage();
    if (xmlNamespaceGenPackage != null) {
      Resource xmlNamespaceResource=resourceSet.createResource(URI.createURI("String_Node_Str"));
      xmlNamespaceResource.getContents().add(xmlNamespaceGenPackage.getGenModel());
    }
    ecoreXcoreBuilder.link();
    genModelBuilder.buildMap(inputGenModel);
    ImportManager importManager=new ImportManager(inputGenPackage.getInterfacePackageName()){
      @Override protected boolean shouldImport(      String packageName,      String shortName,      String importName){
        return true;
      }
    }
;
    Map<EGenericType,XGenericType> genericTypeMap=ecoreXcoreBuilder.getGenericTypeMap();
    for (TreeIterator<EObject> i=inputGenPackage.getEcorePackage().eAllContents(); i.hasNext(); ) {
      EObject eObject=i.next();
      if (eObject instanceof EGenericType) {
        EGenericType eGenericType=(EGenericType)eObject;
        EClassifier eClassifier=eGenericType.getEClassifier();
        if (eClassifier != null) {
          GenClassifier genClassifier=inputGenModel.findGenClassifier(eClassifier);
          QualifiedName qualifiedName=qualifiedNameProvider.getFullyQualifiedName(genClassifier);
          String qualifiedNameValue=qualifiedNameConverter.toString(qualifiedName);
          if (!IMPLICIT_ALIASES.contains(qualifiedNameValue)) {
            importManager.addImport(qualifiedNameValue);
          }
          XGenericType xGenericType=genericTypeMap.get(eGenericType);
          IScope scope=scopeProvider.getScope(xGenericType,XcorePackage.Literals.XGENERIC_TYPE__TYPE);
          IEObjectDescription genClassifierDescription=scope.getSingleElement(qualifiedName);
          if (genClassifierDescription != null) {
            EObject resolvedGenClassifier=resourceSet.getEObject(genClassifierDescription.getEObjectURI(),true);
            if (resolvedGenClassifier != null && resolvedGenClassifier != genClassifier) {
              xGenericType.setType((GenClassifier)resolvedGenClassifier);
            }
          }
        }
      }
 else       if (eObject instanceof EReference) {
        EReference eReference=(EReference)eObject;
        XReference xReference=(XReference)mapper.getToXcoreMapping(eReference).getXcoreElement();
        EList<GenFeature> keys=xReference.getKeys();
        GenFeature opposite=xReference.getOpposite();
        if (opposite != null) {
          IScope scope=scopeProvider.getScope(xReference,XcorePackage.Literals.XREFERENCE__OPPOSITE);
          IEObjectDescription genFeatureDescription=scope.getSingleElement(QualifiedName.create(opposite.getName()));
          if (genFeatureDescription != null) {
            EObject resolvedGenFeature=resourceSet.getEObject(genFeatureDescription.getEObjectURI(),true);
            if (resolvedGenFeature != null) {
              xReference.setOpposite((GenFeature)resolvedGenFeature);
            }
          }
        }
        if (!keys.isEmpty()) {
          IScope scope=scopeProvider.getScope(xReference,XcorePackage.Literals.XREFERENCE__KEYS);
          for (ListIterator<GenFeature> k=keys.listIterator(); k.hasNext(); ) {
            GenFeature key=k.next();
            IEObjectDescription genFeatureDescription=scope.getSingleElement(QualifiedName.create(key.getName()));
            if (genFeatureDescription != null) {
              EObject resolvedGenFeature=resourceSet.getEObject(genFeatureDescription.getEObjectURI(),true);
              if (resolvedGenFeature != null) {
                k.set((GenFeature)resolvedGenFeature);
              }
            }
          }
        }
      }
 else       if (eObject instanceof EPackage) {
        i.prune();
      }
    }
    for (    String qualifiedName : importManager.getImports()) {
      XImportDirective xImportDirective=XcoreFactory.eINSTANCE.createXImportDirective();
      xImportDirective.setImportedNamespace(qualifiedName);
      xPackage.getImportDirectives().add(xImportDirective);
    }
    Map<Object,Object> options=new HashMap<Object,Object>();
    SaveOptions.newBuilder().format().noValidation().getOptions().addTo(options);
    outputResource.save(options);
  }
  return Diagnostic.OK_INSTANCE;
}

Fixed version (ground truth):
@Override protected Diagnostic doExport(Monitor monitor,ModelExporter.ExportData exportData) throws Exception {
  for (  Map.Entry<GenPackage,URI> entry : exportData.genPackageToArtifactURI.entrySet()) {
    GenPackage genPackage=entry.getKey();
    URI xcoreLocationURI=entry.getValue();
    IFile xcoreFile=ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(xcoreLocationURI.toPlatformString(true)));
    final IProject xcoreProject=xcoreFile.getProject();
    if (xcoreProject.isAccessible()) {
      if (!xcoreProject.hasNature(XtextProjectHelper.NATURE_ID)) {
        IProjectDescription description=xcoreProject.getDescription();
        String[] natures=description.getNatureIds();
        String[] newNatures=new String[natures.length + 1];
        System.arraycopy(natures,0,newNatures,0,natures.length);
        newNatures[natures.length]=XtextProjectHelper.NATURE_ID;
        description.setNatureIds(newNatures);
        xcoreProject.setDescription(description,null);
      }
    }
    ResourceSet resourceSet=new ResourceSetImpl();
    resourceSet.getURIConverter().getURIMap().putAll(EcorePlugin.computePlatformURIMap());
    GenModel inputGenModel=(GenModel)resourceSet.getEObject(EcoreUtil.getURI(getGenModel()),true);
    inputGenModel.reconcile();
    Resource inputResource=inputGenModel.eResource();
    final Resource outputResource=resourceSet.createResource(xcoreLocationURI);
    GenModel genModel=GenModelFactory.eINSTANCE.createGenModel();
    List<EPackage> ePackageClones=new ArrayList<EPackage>();
    for (    GenPackage inputGenPackage : inputGenModel.getGenPackages()) {
      ePackageClones.add(inputGenPackage.getEcorePackage());
    }
    genModel.initialize(ePackageClones);
    inputResource.getContents().add(genModel);
    genModelInitializer.initialize(genModel,true);
    final GenPackage inputGenPackage=(GenPackage)resourceSet.getEObject(EcoreUtil.getURI(genPackage),true);
    new Object(){
      void visit(      GenBase genBase1,      GenBase genBase2){
        if (genBase1.eClass() == genBase2.eClass()) {
          for (          EAttribute eAttribute : genBase1.eClass().getEAllAttributes()) {
            if (!eAttribute.isMany() && genBase1.eIsSet(eAttribute)) {
              Object value1=genBase1.eGet(eAttribute);
              Object value2=genBase2.eGet(eAttribute);
              if (value1 == null ? value2 != null : !value1.equals(value2)) {
                EModelElement eModelElement=genBase2.getEcoreModelElement();
                if (eModelElement == null && genBase2 instanceof GenModel) {
                  eModelElement=inputGenPackage.getEcorePackage();
                }
                EcoreUtil.setAnnotation(eModelElement,GenModelPackage.eNS_URI,eAttribute.getName(),EcoreUtil.convertToString(eAttribute.getEAttributeType(),value1));
              }
              for (Iterator<EObject> i=genBase1.eContents().iterator(), j=genBase2.eContents().iterator(); i.hasNext() && j.hasNext(); ) {
                EObject content1=i.next();
                EObject content2=j.next();
                if (content1 instanceof GenBase && content2 instanceof GenBase) {
                  visit((GenBase)content1,(GenBase)content2);
                }
              }
            }
          }
        }
      }
    }
.visit(inputGenModel,genModel);
    EcoreXcoreBuilder ecoreXcoreBuilder=ecoreXcoreBuilderProvider.get();
    ecoreXcoreBuilder.initialize(inputGenModel);
    XPackage xPackage=ecoreXcoreBuilder.getXPackage(inputGenPackage.getEcorePackage());
    outputResource.getContents().add(xPackage);
    outputResource.getContents().add(inputGenModel);
    outputResource.getContents().add(inputGenPackage.getEcorePackage());
    GenPackage ecoreGenPackage=inputGenModel.getEcoreGenPackage();
    if (ecoreGenPackage != null) {
      Resource ecoreResource=resourceSet.createResource(URI.createPlatformResourceURI("String_Node_Str",false));
      ecoreResource.getContents().add(ecoreGenPackage.getGenModel());
    }
    GenPackage xmlTypeGenPackage=inputGenModel.getXMLTypeGenPackage();
    if (xmlTypeGenPackage != null) {
      Resource xmlTypeResource=resourceSet.createResource(URI.createPlatformResourceURI("String_Node_Str",false));
      xmlTypeResource.getContents().add(xmlTypeGenPackage.getGenModel());
    }
    GenPackage xmlNamespaceGenPackage=inputGenModel.getXMLNamespaceGenPackage();
    if (xmlNamespaceGenPackage != null) {
      Resource xmlNamespaceResource=resourceSet.createResource(URI.createPlatformResourceURI("String_Node_Str",false));
      xmlNamespaceResource.getContents().add(xmlNamespaceGenPackage.getGenModel());
    }
    resourceSet.getURIConverter().getURIMap().remove(URI.createPlatformResourceURI("String_Node_Str",false));
    ecoreXcoreBuilder.link();
    genModelBuilder.buildMap(inputGenModel);
    ImportManager importManager=new ImportManager(inputGenPackage.getInterfacePackageName()){
      @Override protected boolean shouldImport(      String packageName,      String shortName,      String importName){
        return true;
      }
    }
;
    Map<EGenericType,XGenericType> genericTypeMap=ecoreXcoreBuilder.getGenericTypeMap();
    for (TreeIterator<EObject> i=inputGenPackage.getEcorePackage().eAllContents(); i.hasNext(); ) {
      EObject eObject=i.next();
      if (eObject instanceof EGenericType) {
        EGenericType eGenericType=(EGenericType)eObject;
        EClassifier eClassifier=eGenericType.getEClassifier();
        if (eClassifier != null) {
          GenClassifier genClassifier=inputGenModel.findGenClassifier(eClassifier);
          QualifiedName qualifiedName=qualifiedNameProvider.getFullyQualifiedName(genClassifier);
          String qualifiedNameValue=qualifiedNameConverter.toString(qualifiedName);
          if (!IMPLICIT_ALIASES.contains(qualifiedNameValue)) {
            importManager.addImport(qualifiedNameValue);
          }
          XGenericType xGenericType=genericTypeMap.get(eGenericType);
          IScope scope=scopeProvider.getScope(xGenericType,XcorePackage.Literals.XGENERIC_TYPE__TYPE);
          IEObjectDescription genClassifierDescription=scope.getSingleElement(qualifiedName);
          if (genClassifierDescription != null) {
            EObject resolvedGenClassifier=resourceSet.getEObject(genClassifierDescription.getEObjectURI(),true);
            if (resolvedGenClassifier != null && resolvedGenClassifier != genClassifier) {
              xGenericType.setType((GenClassifier)resolvedGenClassifier);
            }
          }
        }
      }
 else       if (eObject instanceof EReference) {
        EReference eReference=(EReference)eObject;
        XReference xReference=(XReference)mapper.getToXcoreMapping(eReference).getXcoreElement();
        EList<GenFeature> keys=xReference.getKeys();
        GenFeature opposite=xReference.getOpposite();
        if (opposite != null) {
          IScope scope=scopeProvider.getScope(xReference,XcorePackage.Literals.XREFERENCE__OPPOSITE);
          IEObjectDescription genFeatureDescription=scope.getSingleElement(QualifiedName.create(opposite.getName()));
          if (genFeatureDescription != null) {
            EObject resolvedGenFeature=resourceSet.getEObject(genFeatureDescription.getEObjectURI(),true);
            if (resolvedGenFeature != null) {
              xReference.setOpposite((GenFeature)resolvedGenFeature);
            }
          }
        }
        if (!keys.isEmpty()) {
          IScope scope=scopeProvider.getScope(xReference,XcorePackage.Literals.XREFERENCE__KEYS);
          for (ListIterator<GenFeature> k=keys.listIterator(); k.hasNext(); ) {
            GenFeature key=k.next();
            IEObjectDescription genFeatureDescription=scope.getSingleElement(QualifiedName.create(key.getName()));
            if (genFeatureDescription != null) {
              EObject resolvedGenFeature=resourceSet.getEObject(genFeatureDescription.getEObjectURI(),true);
              if (resolvedGenFeature != null) {
                k.set((GenFeature)resolvedGenFeature);
              }
            }
          }
        }
      }
 else       if (eObject instanceof EPackage) {
        i.prune();
      }
    }
    for (    String qualifiedName : importManager.getImports()) {
      XImportDirective xImportDirective=XcoreFactory.eINSTANCE.createXImportDirective();
      xImportDirective.setImportedNamespace(qualifiedName);
      xPackage.getImportDirectives().add(xImportDirective);
    }
    final Map<Object,Object> options=new HashMap<Object,Object>();
    SaveOptions.newBuilder().format().noValidation().getOptions().addTo(options);
    Job job=new Job("String_Node_Str"){
      @Override protected IStatus run(      IProgressMonitor monitor){
        try {
          outputResource.save(options);
        }
 catch (        IOException exception) {
          return Status.CANCEL_STATUS;
        }
        return Status.OK_STATUS;
      }
    }
;
    job.schedule();
  }
  return Diagnostic.OK_INSTANCE;
}