Program: 68710
Project: 68710
Buggy source:
public void addGlobalElements(HashMap<QName,String> additionalElements){
  for (  QName next : additionalElements.keySet()) {
    String namespaceURI=next.getNamespaceURI();
    Schema targetSchema=getSchemaForNamespace(namespaceURI);
    Element element=new Element();
    element.setName(next.getLocalPart());
    JavaClass javaClass=helper.getJavaClass(additionalElements.get(next));
    QName schemaType=(QName)helper.getXMLToJavaTypeMap().get(javaClass.getRawName());
    if (schemaType != null) {
      element.setType(XMLConstants.SCHEMA_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)) {
          element.setType(schemaType.getLocalPart());
        }
 else {
          Schema complexTypeSchema=getSchemaForNamespace(type.getClassNamespace());
          String complexTypeSchemaNS=complexTypeSchema.getTargetNamespace();
          if (complexTypeSchemaNS == null) {
            complexTypeSchemaNS="String_Node_Str";
          }
          if (targetSchema.getImports().get(complexTypeSchema.getName()) == null) {
            Import schemaImport=new Import();
            schemaImport.setNamespace(complexTypeSchema.getTargetNamespace());
            schemaImport.setSchemaLocation(complexTypeSchema.getName());
            targetSchema.getImports().put(schemaImport.getSchemaLocation(),schemaImport);
            if (!complexTypeSchemaNS.equals("String_Node_Str")) {
              targetSchema.getNamespaceResolver().put(targetSchema.getNamespaceResolver().generatePrefix(),complexTypeSchemaNS);
            }
          }
          String prefix=targetSchema.getNamespaceResolver().resolveNamespaceURI(complexTypeSchema.getTargetNamespace());
          element.setType(prefix + "String_Node_Str" + typeName);
        }
      }
    }
    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,String> additionalElements){
  for (  QName next : additionalElements.keySet()) {
    String namespaceURI=next.getNamespaceURI();
    Schema targetSchema=getSchemaForNamespace(namespaceURI);
    Element element=new Element();
    element.setName(next.getLocalPart());
    JavaClass javaClass=helper.getJavaClass(additionalElements.get(next));
    QName schemaType=(QName)helper.getXMLToJavaTypeMap().get(javaClass.getRawName());
    if (schemaType != null) {
      element.setType(XMLConstants.SCHEMA_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)) {
          element.setType(schemaType.getLocalPart());
        }
 else {
          Schema complexTypeSchema=getSchemaForNamespace(type.getClassNamespace());
          String complexTypeSchemaNS=complexTypeSchema.getTargetNamespace();
          if (complexTypeSchemaNS == null) {
            complexTypeSchemaNS="String_Node_Str";
          }
          if (!importExists(targetSchema,complexTypeSchema.getName())) {
            Import schemaImport=new Import();
            schemaImport.setNamespace(complexTypeSchema.getTargetNamespace());
            schemaImport.setSchemaLocation(complexTypeSchema.getName());
            targetSchema.getImports().add(schemaImport);
            if (!complexTypeSchemaNS.equals("String_Node_Str")) {
              targetSchema.getNamespaceResolver().put(targetSchema.getNamespaceResolver().generatePrefix(),complexTypeSchemaNS);
            }
          }
          String prefix=targetSchema.getNamespaceResolver().resolveNamespaceURI(complexTypeSchema.getTargetNamespace());
          element.setType(prefix + "String_Node_Str" + typeName);
        }
      }
    }
    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);
  }
}