Program: 66537
Project: 66537
Buggy source:
public void addGlobalElements(HashMap<QName,ElementDeclaration> additionalElements){
  for (  QName next : additionalElements.keySet()) {
    if (next != null) {
      ElementDeclaration nextElement=additionalElements.get(next);
      if (nextElement.getScopeClass() == GLOBAL.class) {
        String namespaceURI=next.getNamespaceURI();
        Schema targetSchema=getSchemaForNamespace(namespaceURI);
        if (targetSchema == null) {
          break;
        }
        if (targetSchema.getTopLevelElements().get(next.getLocalPart()) == null) {
          Element element=new Element();
          element.setName(next.getLocalPart());
          JavaClass javaClass=nextElement.getJavaType();
          QName schemaType=(QName)helper.getXMLToJavaTypeMap().get(javaClass.getRawName());
          if (schemaType != null) {
            element.setType(XMLConstants.SCHEMA_PREFIX + "String_Node_Str" + schemaType.getLocalPart());
          }
 else           if (areEquals(javaClass,JAVAX_ACTIVATION_DATAHANDLER) || areEquals(javaClass,byte[].class) || areEquals(javaClass,Byte[].class)|| areEquals(javaClass,Image.class)|| areEquals(javaClass,Source.class)|| areEquals(javaClass,JAVAX_MAIL_INTERNET_MIMEMULTIPART)) {
            schemaType=XMLConstants.BASE_64_BINARY_QNAME;
            if (nextElement.getTypeMappingInfo() != null) {
              if (nextElement.isXmlAttachmentRef()) {
                schemaType=XMLConstants.SWA_REF_QNAME;
              }
              if (nextElement.getXmlMimeType() != null) {
                element.getAttributesMap().put(XMLConstants.EXPECTED_CONTENT_TYPES_QNAME,nextElement.getXmlMimeType());
              }
            }
            String prefix=getOrGeneratePrefixForNamespace(schemaType.getNamespaceURI(),targetSchema);
            element.setType(prefix + "String_Node_Str" + schemaType.getLocalPart());
          }
 else {
            TypeInfo type=(TypeInfo)this.typeInfo.get(javaClass.getQualifiedName());
            if (type != null) {
              String typeName=null;
              if (type.isComplexType()) {
                typeName=type.getComplexType().getName();
              }
 else {
                typeName=type.getSimpleType().getName();
              }
              if (type.getClassNamespace().equals(namespaceURI)) {
                String prefix=targetSchema.getNamespaceResolver().resolveNamespaceURI(namespaceURI);
                if (prefix != null && !(prefix.equals("String_Node_Str"))) {
                  element.setType(prefix + "String_Node_Str" + typeName);
                }
 else {
                  element.setType(typeName);
                }
              }
 else {
                Schema complexTypeSchema=getSchemaForNamespace(type.getClassNamespace());
                String complexTypeSchemaNS=type.getClassNamespace();
                if (complexTypeSchemaNS == null) {
                  complexTypeSchemaNS="String_Node_Str";
                }
                addImportIfRequired(targetSchema,complexTypeSchema,type.getClassNamespace());
                String prefix=targetSchema.getNamespaceResolver().resolveNamespaceURI(complexTypeSchemaNS);
                if (prefix != null) {
                  element.setType(prefix + "String_Node_Str" + typeName);
                }
 else {
                  element.setType(typeName);
                }
              }
            }
          }
          if (nextElement.getSubstitutionHead() != null) {
            String subLocal=nextElement.getSubstitutionHead().getLocalPart();
            String subNamespace=nextElement.getSubstitutionHead().getNamespaceURI();
            String prefix=getPrefixForNamespace(subNamespace,targetSchema.getNamespaceResolver());
            if (prefix == null || prefix.equals("String_Node_Str")) {
              element.setSubstitutionGroup(subLocal);
            }
 else {
              element.setSubstitutionGroup(prefix + "String_Node_Str" + subLocal);
            }
          }
          targetSchema.addTopLevelElement(element);
          SchemaTypeInfo info=this.schemaTypeInfo.get(javaClass.getQualifiedName());
          if (info == null) {
            info=new SchemaTypeInfo();
            info.setSchemaTypeName(schemaType);
            schemaTypeInfo.put(javaClass.getQualifiedName(),info);
          }
          info.getGlobalElementDeclarations().add(next);
        }
      }
    }
  }
}

Fixed version (ground truth):
public void addGlobalElements(HashMap<QName,ElementDeclaration> additionalElements){
  for (  Entry<QName,ElementDeclaration> entry : additionalElements.entrySet()) {
    QName next=entry.getKey();
    if (next != null) {
      ElementDeclaration nextElement=entry.getValue();
      if (nextElement.getScopeClass() == GLOBAL.class) {
        String namespaceURI=next.getNamespaceURI();
        Schema targetSchema=getSchemaForNamespace(namespaceURI);
        if (targetSchema == null) {
          break;
        }
        if (targetSchema.getTopLevelElements().get(next.getLocalPart()) == null) {
          Element element=new Element();
          element.setName(next.getLocalPart());
          JavaClass javaClass=nextElement.getJavaType();
          QName schemaType=(QName)helper.getXMLToJavaTypeMap().get(javaClass.getRawName());
          if (schemaType != null) {
            element.setType(XMLConstants.SCHEMA_PREFIX + "String_Node_Str" + schemaType.getLocalPart());
          }
 else           if (areEquals(javaClass,JAVAX_ACTIVATION_DATAHANDLER) || areEquals(javaClass,byte[].class) || areEquals(javaClass,Byte[].class)|| areEquals(javaClass,Image.class)|| areEquals(javaClass,Source.class)|| areEquals(javaClass,JAVAX_MAIL_INTERNET_MIMEMULTIPART)) {
            schemaType=XMLConstants.BASE_64_BINARY_QNAME;
            if (nextElement.getTypeMappingInfo() != null) {
              if (nextElement.isXmlAttachmentRef()) {
                schemaType=XMLConstants.SWA_REF_QNAME;
              }
              if (nextElement.getXmlMimeType() != null) {
                element.getAttributesMap().put(XMLConstants.EXPECTED_CONTENT_TYPES_QNAME,nextElement.getXmlMimeType());
              }
            }
            String prefix=getOrGeneratePrefixForNamespace(schemaType.getNamespaceURI(),targetSchema);
            element.setType(prefix + "String_Node_Str" + schemaType.getLocalPart());
          }
 else {
            TypeInfo type=(TypeInfo)this.typeInfo.get(javaClass.getQualifiedName());
            if (type != null) {
              String typeName=null;
              if (type.isComplexType()) {
                typeName=type.getComplexType().getName();
              }
 else {
                typeName=type.getSimpleType().getName();
              }
              if (type.getClassNamespace().equals(namespaceURI)) {
                String prefix=targetSchema.getNamespaceResolver().resolveNamespaceURI(namespaceURI);
                if (prefix != null && !(prefix.equals("String_Node_Str"))) {
                  element.setType(prefix + "String_Node_Str" + typeName);
                }
 else {
                  element.setType(typeName);
                }
              }
 else {
                Schema complexTypeSchema=getSchemaForNamespace(type.getClassNamespace());
                String complexTypeSchemaNS=type.getClassNamespace();
                if (complexTypeSchemaNS == null) {
                  complexTypeSchemaNS="String_Node_Str";
                }
                addImportIfRequired(targetSchema,complexTypeSchema,type.getClassNamespace());
                String prefix=targetSchema.getNamespaceResolver().resolveNamespaceURI(complexTypeSchemaNS);
                if (prefix != null) {
                  element.setType(prefix + "String_Node_Str" + typeName);
                }
 else {
                  element.setType(typeName);
                }
              }
            }
          }
          if (nextElement.getSubstitutionHead() != null) {
            String subLocal=nextElement.getSubstitutionHead().getLocalPart();
            String subNamespace=nextElement.getSubstitutionHead().getNamespaceURI();
            String prefix=getPrefixForNamespace(subNamespace,targetSchema.getNamespaceResolver());
            if (prefix == null || prefix.equals("String_Node_Str")) {
              element.setSubstitutionGroup(subLocal);
            }
 else {
              element.setSubstitutionGroup(prefix + "String_Node_Str" + subLocal);
            }
          }
          targetSchema.addTopLevelElement(element);
          SchemaTypeInfo info=this.schemaTypeInfo.get(javaClass.getQualifiedName());
          if (info == null) {
            info=new SchemaTypeInfo();
            info.setSchemaTypeName(schemaType);
            schemaTypeInfo.put(javaClass.getQualifiedName(),info);
          }
          info.getGlobalElementDeclarations().add(next);
        }
      }
    }
  }
}