Program: 11934
Project: 11934
Buggy source:
protected void addNamespaceDeclarations(){
  EPackage noNamespacePackage=helper.getNoNamespacePackage();
  EPackage[] packages=helper.packages();
  StringBuffer xsiSchemaLocation=null;
  String xsiNoNamespaceSchemaLocation=null;
  if (declareSchemaLocation) {
    if (extendedMetaData == null) {
      for (int i=0; i < packages.length; i++) {
        EPackage ePackage=packages[i];
        if (noNamespacePackage == ePackage) {
          declareXSI=true;
          if (ePackage.eResource() != null) {
            xsiNoNamespaceSchemaLocation=helper.getHREF(ePackage);
            if (xsiNoNamespaceSchemaLocation.endsWith("String_Node_Str")) {
              xsiNoNamespaceSchemaLocation=xsiNoNamespaceSchemaLocation.substring(0,xsiNoNamespaceSchemaLocation.length() - 2);
            }
          }
        }
 else {
          Resource resource=ePackage.eResource();
          if (resource != null) {
            URI uri=resource.getURI();
            String nsURI=ePackage.getNsURI();
            if (uri == null ? nsURI != null : !uri.toString().equals(nsURI)) {
              declareXSI=true;
              if (xsiSchemaLocation == null) {
                xsiSchemaLocation=new StringBuffer();
              }
 else {
                xsiSchemaLocation.append(' ');
              }
              xsiSchemaLocation.append(nsURI);
              xsiSchemaLocation.append(' ');
              String location=helper.getHREF(ePackage);
              if (location.endsWith("String_Node_Str")) {
                location=location.substring(0,location.length() - 2);
              }
              xsiSchemaLocation.append(location);
            }
          }
        }
      }
    }
 else {
      Resource resource=helper.getResource();
      if (resource != null && resource.getContents().size() >= 1) {
        EObject root=(EObject)resource.getContents().get(0);
        EClass eClass=root.eClass();
        EReference xsiSchemaLocationMapFeature=extendedMetaData.getXSISchemaLocationMapFeature(eClass);
        if (xsiSchemaLocationMapFeature != null) {
          EMap xsiSchemaLocationMap=(EMap)root.eGet(xsiSchemaLocationMapFeature);
          if (!xsiSchemaLocationMap.isEmpty()) {
            declareXSI=true;
            for (Iterator i=xsiSchemaLocationMap.entrySet().iterator(); i.hasNext(); ) {
              Map.Entry entry=(Map.Entry)i.next();
              String namespace=(String)entry.getKey();
              URI location=URI.createURI(entry.getValue().toString());
              if (namespace == null) {
                xsiNoNamespaceSchemaLocation=helper.deresolve(location).toString();
              }
 else {
                if (xsiSchemaLocation == null) {
                  xsiSchemaLocation=new StringBuffer();
                }
 else {
                  xsiSchemaLocation.append(' ');
                }
                xsiSchemaLocation.append(namespace);
                xsiSchemaLocation.append(' ');
                xsiSchemaLocation.append(helper.deresolve(location).toString());
              }
            }
          }
        }
      }
    }
  }
  if (declareXSI) {
    doc.addAttribute(XSI_XMLNS,XMLResource.XSI_URI);
  }
  for (int i=0; i < packages.length; i++) {
    EPackage ePackage=packages[i];
    if (ePackage != noNamespacePackage && ePackage != XMLNamespacePackage.eINSTANCE) {
      String nsURI=extendedMetaData == null ? ePackage.getNsURI() : extendedMetaData.getNamespace(ePackage);
      if (nsURI != null) {
        List nsPrefixes=helper.getPrefixes(ePackage);
        for (Iterator j=nsPrefixes.iterator(); j.hasNext(); ) {
          String nsPrefix=(String)j.next();
          if (nsPrefix != null && nsPrefix.length() > 0) {
            doc.addAttributeNS(XMLResource.XML_NS,nsPrefix,nsURI);
          }
 else {
            doc.addAttribute(XMLResource.XML_NS,nsURI);
          }
        }
      }
    }
  }
  if (xsiSchemaLocation != null) {
    doc.addAttribute(XSI_SCHEMA_LOCATION,xsiSchemaLocation.toString());
  }
  if (xsiNoNamespaceSchemaLocation != null) {
    doc.addAttribute(XSI_NO_NAMESPACE_SCHEMA_LOCATION,xsiNoNamespaceSchemaLocation);
  }
}

Fixed version (ground truth):
protected void addNamespaceDeclarations(){
  EPackage noNamespacePackage=helper.getNoNamespacePackage();
  EPackage[] packages=helper.packages();
  StringBuffer xsiSchemaLocation=null;
  String xsiNoNamespaceSchemaLocation=null;
  if (declareSchemaLocation) {
    if (extendedMetaData == null) {
      for (int i=0; i < packages.length; i++) {
        EPackage ePackage=packages[i];
        if (noNamespacePackage == ePackage) {
          declareXSI=true;
          if (ePackage.eResource() != null) {
            xsiNoNamespaceSchemaLocation=helper.getHREF(ePackage);
            if (xsiNoNamespaceSchemaLocation.endsWith("String_Node_Str")) {
              xsiNoNamespaceSchemaLocation=xsiNoNamespaceSchemaLocation.substring(0,xsiNoNamespaceSchemaLocation.length() - 2);
            }
          }
        }
 else {
          Resource resource=ePackage.eResource();
          if (resource != null) {
            URI uri=resource.getURI();
            String nsURI=ePackage.getNsURI();
            if (uri == null ? nsURI != null : !uri.toString().equals(nsURI)) {
              declareXSI=true;
              if (xsiSchemaLocation == null) {
                xsiSchemaLocation=new StringBuffer();
              }
 else {
                xsiSchemaLocation.append(' ');
              }
              xsiSchemaLocation.append(nsURI);
              xsiSchemaLocation.append(' ');
              String location=helper.getHREF(ePackage);
              if (location.endsWith("String_Node_Str")) {
                location=location.substring(0,location.length() - 2);
              }
              xsiSchemaLocation.append(location);
            }
          }
        }
      }
    }
 else {
      Resource resource=helper.getResource();
      if (resource != null && resource.getContents().size() >= 1) {
        EObject root=(EObject)resource.getContents().get(0);
        EClass eClass=root.eClass();
        EReference xsiSchemaLocationMapFeature=extendedMetaData.getXSISchemaLocationMapFeature(eClass);
        if (xsiSchemaLocationMapFeature != null) {
          EMap xsiSchemaLocationMap=(EMap)root.eGet(xsiSchemaLocationMapFeature);
          if (!xsiSchemaLocationMap.isEmpty()) {
            declareXSI=true;
            for (Iterator i=xsiSchemaLocationMap.entrySet().iterator(); i.hasNext(); ) {
              Map.Entry entry=(Map.Entry)i.next();
              String namespace=(String)entry.getKey();
              URI location=URI.createURI(entry.getValue().toString());
              if (namespace == null) {
                xsiNoNamespaceSchemaLocation=helper.deresolve(location).toString();
              }
 else {
                if (xsiSchemaLocation == null) {
                  xsiSchemaLocation=new StringBuffer();
                }
 else {
                  xsiSchemaLocation.append(' ');
                }
                xsiSchemaLocation.append(namespace);
                xsiSchemaLocation.append(' ');
                xsiSchemaLocation.append(helper.deresolve(location).toString());
              }
            }
          }
        }
      }
    }
  }
  if (declareXSI) {
    doc.addAttribute(XSI_XMLNS,XMLResource.XSI_URI);
  }
  for (int i=0; i < packages.length; i++) {
    EPackage ePackage=packages[i];
    if (ePackage != noNamespacePackage && ePackage != XMLNamespacePackage.eINSTANCE) {
      String nsURI=extendedMetaData == null ? ePackage.getNsURI() : extendedMetaData.getNamespace(ePackage);
      if (nsURI != null && !isDuplicateURI(nsURI)) {
        List nsPrefixes=helper.getPrefixes(ePackage);
        for (Iterator j=nsPrefixes.iterator(); j.hasNext(); ) {
          String nsPrefix=(String)j.next();
          if (nsPrefix != null && nsPrefix.length() > 0) {
            doc.addAttributeNS(XMLResource.XML_NS,nsPrefix,nsURI);
          }
 else {
            doc.addAttribute(XMLResource.XML_NS,nsURI);
          }
        }
      }
    }
  }
  if (xsiSchemaLocation != null) {
    doc.addAttribute(XSI_SCHEMA_LOCATION,xsiSchemaLocation.toString());
  }
  if (xsiNoNamespaceSchemaLocation != null) {
    doc.addAttribute(XSI_NO_NAMESPACE_SCHEMA_LOCATION,xsiNoNamespaceSchemaLocation);
  }
}