Program: 11777
Project: 11777
Buggy source:
protected void generatePackageSerialization(GenPackage genPackage,Monitor monitor){
  if (genPackage.hasClassifiers() && genPackage.isLoadingInitialization()) {
    monitor=createMonitor(monitor,1);
    try {
      monitor.beginTask("String_Node_Str",2);
      GenModel genModel=genPackage.getGenModel();
      String targetPathName=genModel.getModelDirectory() + "String_Node_Str" + genPackage.getClassPackageName().replace('.','/')+ "String_Node_Str"+ genPackage.getSerializedPackageFilename();
      message=CodeGenEcorePlugin.INSTANCE.getString("String_Node_Str",new Object[]{targetPathName});
      monitor.subTask(message);
      URI targetFile=toURI(targetPathName);
      ensureContainerExists(targetFile.trimSegments(1),createMonitor(monitor,1));
      EPackage originalPackage=genPackage.getEcorePackage();
      Resource originalResource=originalPackage.eResource();
      ResourceSet set=new ResourceSetImpl();
      set.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION,new EcoreResourceFactoryImpl());
      URI targetURI=toPlatformResourceURI(targetFile);
      Resource outputResource=set.createResource(targetFile);
      EPackage outputPackage=(EPackage)EcoreUtil.copy(originalPackage);
      outputResource.getContents().add(outputPackage);
      for (Iterator<EObject> i=outputResource.getAllContents(); i.hasNext(); ) {
        EObject eObject=i.next();
        if (eObject instanceof EModelElement) {
          EModelElement eModelElement=(EModelElement)eObject;
          for (Iterator<EAnnotation> j=eModelElement.getEAnnotations().iterator(); j.hasNext(); ) {
            EAnnotation eAnnotation=j.next();
            if (genModel.isSuppressedAnnotation(eAnnotation.getSource())) {
              j.remove();
            }
          }
        }
      }
      collapseEmptyPackages(outputPackage);
      final Map<URI,URI> uriMap=new HashMap<URI,URI>();
      for (      Resource resource : originalResource.getResourceSet().getResources()) {
        List<EObject> contents=resource.getContents();
        if (!contents.isEmpty() && contents.get(0) instanceof EPackage) {
          EPackage ePackage=(EPackage)contents.get(0);
          uriMap.put(resource.getURI(),resource == originalResource ? targetURI : URI.createURI(ePackage.getNsURI()));
        }
      }
      XMLResource.URIHandler uriHandler=new URIHandlerImpl.PlatformSchemeAware(){
        protected URI redirect(        URI uri){
          URI mappedURI=uriMap.get(uri.trimFragment());
          return mappedURI == null ? uri : mappedURI.appendFragment(uri.fragment());
        }
        @Override public URI deresolve(        URI uri){
          return super.deresolve(redirect(uri));
        }
        @Override public URI resolve(        URI uri){
          return super.resolve(redirect(uri));
        }
        @Override public void setBaseURI(        URI uri){
          super.setBaseURI(redirect(uri));
        }
      }
;
      Map<Object,Object> options=new HashMap<Object,Object>();
      options.put(XMLResource.OPTION_URI_HANDLER,uriHandler);
      try {
        outputResource.save(options);
      }
 catch (      IOException exception) {
        CodeGenEcorePlugin.INSTANCE.log(exception);
      }
    }
  finally {
      monitor.done();
    }
  }
 else {
    monitor.worked(1);
  }
}

Fixed version (ground truth):
protected void generatePackageSerialization(GenPackage genPackage,Monitor monitor){
  if (genPackage.hasClassifiers() && genPackage.isLoadingInitialization()) {
    monitor=createMonitor(monitor,1);
    try {
      monitor.beginTask("String_Node_Str",2);
      final GenModel genModel=genPackage.getGenModel();
      String targetPathName=genModel.getModelDirectory() + "String_Node_Str" + genPackage.getClassPackageName().replace('.','/')+ "String_Node_Str"+ genPackage.getSerializedPackageFilename();
      message=CodeGenEcorePlugin.INSTANCE.getString("String_Node_Str",new Object[]{targetPathName});
      monitor.subTask(message);
      URI targetFile=toURI(targetPathName);
      ensureContainerExists(targetFile.trimSegments(1),createMonitor(monitor,1));
      EPackage originalPackage=genPackage.getEcorePackage();
      Resource originalResource=originalPackage.eResource();
      ResourceSet set=new ResourceSetImpl();
      set.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION,new EcoreResourceFactoryImpl());
      URI targetURI=toPlatformResourceURI(targetFile);
      Resource outputResource=set.createResource(targetURI);
      EcoreUtil.Copier copier=new EcoreUtil.Copier(){
        private static final long serialVersionUID=1L;
        @Override protected void copyContainment(        EReference reference,        EObject object,        EObject copyEObject){
          if (reference == EcorePackage.Literals.EMODEL_ELEMENT__EANNOTATIONS) {
            List<EAnnotation> result=((EModelElement)copyEObject).getEAnnotations();
            result.clear();
            for (            EAnnotation eAnnotation : ((EModelElement)object).getEAnnotations()) {
              if (!genModel.isSuppressedAnnotation(eAnnotation.getSource())) {
                result.add((EAnnotation)copy(eAnnotation));
              }
            }
            return;
          }
          super.copyContainment(reference,object,copyEObject);
        }
      }
;
      EPackage outputPackage=(EPackage)copier.copy(originalPackage);
      copier.copyReferences();
      outputResource.getContents().add(outputPackage);
      collapseEmptyPackages(outputPackage);
      final Map<URI,URI> uriMap=new HashMap<URI,URI>();
      for (      Resource resource : originalResource.getResourceSet().getResources()) {
        List<EObject> contents=resource.getContents();
        if (!contents.isEmpty() && contents.get(0) instanceof EPackage) {
          if (resource != originalResource) {
            uriMap.put(resource.getURI(),URI.createURI(((EPackage)contents.get(0)).getNsURI()));
          }
        }
      }
      XMLResource.URIHandler uriHandler=new URIHandlerImpl.PlatformSchemeAware(){
        protected URI redirect(        URI uri){
          URI mappedURI=uriMap.get(uri.trimFragment());
          return mappedURI == null ? uri : mappedURI.appendFragment(uri.fragment());
        }
        @Override public URI deresolve(        URI uri){
          return super.deresolve(redirect(uri));
        }
        @Override public URI resolve(        URI uri){
          return super.resolve(redirect(uri));
        }
        @Override public void setBaseURI(        URI uri){
          super.setBaseURI(redirect(uri));
        }
      }
;
      Map<Object,Object> options=new HashMap<Object,Object>();
      options.put(XMLResource.OPTION_URI_HANDLER,uriHandler);
      options.put(Resource.OPTION_SAVE_ONLY_IF_CHANGED,Resource.OPTION_SAVE_ONLY_IF_CHANGED_MEMORY_BUFFER);
      try {
        outputResource.save(options);
      }
 catch (      IOException exception) {
        CodeGenEcorePlugin.INSTANCE.log(exception);
      }
    }
  finally {
      monitor.done();
    }
  }
 else {
    monitor.worked(1);
  }
}