Program: 66528
Project: 66528
Buggy source:
/** 
 * Process XmlBindings on a per package basis for a given AnnotationsPorcessor instance.
 * @param annotationsProcessor
 */
public void processXML(AnnotationsProcessor annotationsProcessor,JavaModelInput jModelInput,TypeMappingInfo[] typeMappingInfos,JavaClass[] originalJavaClasses){
  this.jModelInput=jModelInput;
  this.aProcessor=annotationsProcessor;
  Map<String,XmlEnum> xmlEnumMap=new HashMap<String,XmlEnum>();
  annotationsProcessor.init(originalJavaClasses,typeMappingInfos);
  Map<String,ArrayList<JavaClass>> pkgToClassMap=buildPackageToJavaClassMap();
  XmlBindings xmlBindings;
  for (  String packageName : xmlBindingMap.keySet()) {
    ArrayList classesToProcess=pkgToClassMap.get(packageName);
    if (classesToProcess == null) {
      getLogger().logWarning("String_Node_Str",new Object[]{packageName});
      continue;
    }
    xmlBindings=xmlBindingMap.get(packageName);
    NamespaceInfo nsInfo=processXmlSchema(xmlBindings,packageName);
    if (nsInfo != null) {
      annotationsProcessor.addPackageToNamespaceMapping(packageName,nsInfo);
    }
    XmlRegistries xmlRegs=xmlBindings.getXmlRegistries();
    if (xmlRegs != null) {
      for (      XmlRegistry xmlReg : xmlRegs.getXmlRegistry()) {
        aProcessor.addXmlRegistry(xmlReg.getName(),xmlReg);
      }
    }
    JavaClass[] javaClasses=(JavaClass[])classesToProcess.toArray(new JavaClass[classesToProcess.size()]);
    XmlEnums xmlEnums=xmlBindings.getXmlEnums();
    if (xmlEnums != null) {
      for (      XmlEnum xmlEnum : xmlEnums.getXmlEnum()) {
        xmlEnumMap.put(xmlEnum.getJavaEnum(),xmlEnum);
      }
    }
    Map<String,TypeInfo> typeInfoMap=annotationsProcessor.preBuildTypeInfo(javaClasses);
    List<XmlSchemaType> xmlSchemaTypes=null;
    XmlSchemaTypes sTypes=xmlBindings.getXmlSchemaTypes();
    if (sTypes != null) {
      xmlSchemaTypes=sTypes.getXmlSchemaType();
    }
 else {
      xmlSchemaTypes=new ArrayList<XmlSchemaType>();
    }
    if (xmlBindings.getXmlSchemaType() != null) {
      xmlSchemaTypes.add(xmlBindings.getXmlSchemaType());
    }
    for (    XmlSchemaType sType : xmlSchemaTypes) {
      JavaClass jClass=aProcessor.getHelper().getJavaClass(sType.getType());
      if (jClass != null) {
        aProcessor.processSchemaType(sType.getName(),sType.getNamespace(),jClass.getQualifiedName());
      }
    }
    nsInfo=annotationsProcessor.getPackageToNamespaceMappings().get(packageName);
    JavaTypes jTypes=xmlBindings.getJavaTypes();
    if (jTypes != null) {
      for (      JavaType javaType : jTypes.getJavaType()) {
        TypeInfo info=typeInfoMap.get(javaType.getName());
        if (javaType.getXmlJavaTypeAdapter() != null) {
          info.setXmlJavaTypeAdapter(javaType.getXmlJavaTypeAdapter());
        }
        if (javaType.isSetXmlAccessorOrder()) {
          info.setXmlAccessOrder(javaType.getXmlAccessorOrder());
        }
 else         if (!info.isSetXmlAccessOrder()) {
          if (xmlBindings.isSetXmlAccessorOrder()) {
            info.setXmlAccessOrder(xmlBindings.getXmlAccessorOrder());
          }
 else {
            info.setXmlAccessOrder(nsInfo.getAccessOrder());
          }
        }
        if (javaType.isSetXmlAccessorType()) {
          info.setXmlAccessType(javaType.getXmlAccessorType());
        }
 else         if (!info.isSetXmlAccessType()) {
          if (xmlBindings.isSetXmlAccessorType()) {
            info.setXmlAccessType(xmlBindings.getXmlAccessorType());
          }
 else {
            info.setXmlAccessType(nsInfo.getAccessType());
          }
        }
        if (javaType.isSetXmlInlineBinaryData()) {
          info.setInlineBinaryData(javaType.isXmlInlineBinaryData());
        }
        if (javaType.isSetXmlTransient()) {
          info.setXmlTransient(javaType.isXmlTransient());
        }
        if (javaType.getXmlRootElement() != null) {
          info.setXmlRootElement(javaType.getXmlRootElement());
        }
        if (javaType.getXmlSeeAlso() != null && javaType.getXmlSeeAlso().size() > 0) {
          info.setXmlSeeAlso(javaType.getXmlSeeAlso());
        }
        if (javaType.getXmlType() != null) {
          info.setXmlType(javaType.getXmlType());
        }
        if (javaType.getXmlCustomizer() != null) {
          info.setXmlCustomizer(javaType.getXmlCustomizer());
        }
      }
    }
    if (xmlBindings.getXmlJavaTypeAdapters() != null) {
      Map<String,TypeInfo> typeInfos=aProcessor.getTypeInfosForPackage(packageName);
      for (      TypeInfo tInfo : typeInfos.values()) {
        List<XmlJavaTypeAdapter> adapters=xmlBindings.getXmlJavaTypeAdapters().getXmlJavaTypeAdapter();
        for (        XmlJavaTypeAdapter xja : adapters) {
          JavaClass adapterClass=jModelInput.getJavaModel().getClass(xja.getValue());
          JavaClass boundType=jModelInput.getJavaModel().getClass(xja.getType());
          if (boundType != null) {
            tInfo.addPackageLevelAdapterClass(adapterClass,boundType);
          }
        }
      }
    }
    javaClasses=annotationsProcessor.postBuildTypeInfo(javaClasses);
    annotationsProcessor.processJavaClasses(javaClasses);
    Map<String,TypeInfo> typeInfosForPackage=annotationsProcessor.getTypeInfosForPackage(packageName);
    for (    Entry<String,TypeInfo> entry : typeInfosForPackage.entrySet()) {
      TypeInfo tInfo=entry.getValue();
      if (tInfo.isEnumerationType()) {
        EnumTypeInfo etInfo=(EnumTypeInfo)tInfo;
        XmlEnum xmlEnum=xmlEnumMap.get(etInfo.getClassName());
        if (xmlEnum != null) {
          JavaClass restrictionClass=aProcessor.getHelper().getJavaClass(xmlEnum.getValue());
          if (restrictionClass == null) {
            restrictionClass=jModelInput.getJavaModel().getClass(String.class);
          }
          etInfo.setRestrictionBase(aProcessor.getSchemaTypeFor(restrictionClass));
          for (          XmlEnumValue xmlEnumValue : xmlEnum.getXmlEnumValue()) {
            etInfo.addJavaFieldToXmlEnumValuePair(true,xmlEnumValue.getJavaEnumValue(),xmlEnumValue.getValue());
          }
        }
      }
    }
    jTypes=xmlBindings.getJavaTypes();
    if (jTypes != null) {
      for (      JavaType javaType : jTypes.getJavaType()) {
        processJavaType(javaType,typeInfosForPackage.get(javaType.getName()),nsInfo);
      }
    }
    pkgToClassMap.remove(packageName);
  }
  Iterator<ArrayList<JavaClass>> classIt=pkgToClassMap.values().iterator();
  while (classIt.hasNext()) {
    ArrayList<JavaClass> jClassList=classIt.next();
    JavaClass[] jClassArray=(JavaClass[])jClassList.toArray(new JavaClass[jClassList.size()]);
    annotationsProcessor.buildNewTypeInfo(jClassArray);
    annotationsProcessor.processJavaClasses(jClassArray);
  }
  Map<String,TypeInfo> typeInfos=(Map<String,TypeInfo>)aProcessor.getTypeInfo().clone();
  for (  String key : typeInfos.keySet()) {
    JavaClass[] jClassArray;
    TypeInfo tInfo=typeInfos.get(key);
    for (    Property prop : tInfo.getPropertyList()) {
      if (prop.isSetXmlJavaTypeAdapter()) {
        jClassArray=new JavaClass[]{prop.getActualType()};
        aProcessor.buildNewTypeInfo(jClassArray);
      }
    }
  }
  aProcessor.finalizeProperties();
  aProcessor.createElementsForTypeMappingInfo();
}

Fixed version (ground truth):
/** 
 * Process XmlBindings on a per package basis for a given AnnotationsPorcessor instance.
 * @param annotationsProcessor
 */
public void processXML(AnnotationsProcessor annotationsProcessor,JavaModelInput jModelInput,TypeMappingInfo[] typeMappingInfos,JavaClass[] originalJavaClasses){
  this.jModelInput=jModelInput;
  this.aProcessor=annotationsProcessor;
  Map<String,XmlEnum> xmlEnumMap=new HashMap<String,XmlEnum>();
  annotationsProcessor.init(originalJavaClasses,typeMappingInfos);
  Map<String,ArrayList<JavaClass>> pkgToClassMap=buildPackageToJavaClassMap();
  XmlBindings xmlBindings;
  for (  String packageName : xmlBindingMap.keySet()) {
    ArrayList classesToProcess=pkgToClassMap.get(packageName);
    if (classesToProcess == null) {
      getLogger().logWarning("String_Node_Str",new Object[]{packageName});
      continue;
    }
    xmlBindings=xmlBindingMap.get(packageName);
    NamespaceInfo nsInfo=processXmlSchema(xmlBindings,packageName);
    if (nsInfo != null) {
      annotationsProcessor.addPackageToNamespaceMapping(packageName,nsInfo);
    }
    XmlRegistries xmlRegs=xmlBindings.getXmlRegistries();
    if (xmlRegs != null) {
      for (      XmlRegistry xmlReg : xmlRegs.getXmlRegistry()) {
        aProcessor.addXmlRegistry(xmlReg.getName(),xmlReg);
      }
    }
    JavaClass[] javaClasses=(JavaClass[])classesToProcess.toArray(new JavaClass[classesToProcess.size()]);
    XmlEnums xmlEnums=xmlBindings.getXmlEnums();
    if (xmlEnums != null) {
      for (      XmlEnum xmlEnum : xmlEnums.getXmlEnum()) {
        xmlEnumMap.put(xmlEnum.getJavaEnum(),xmlEnum);
      }
    }
    Map<String,TypeInfo> typeInfoMap=annotationsProcessor.preBuildTypeInfo(javaClasses);
    List<XmlSchemaType> xmlSchemaTypes=null;
    XmlSchemaTypes sTypes=xmlBindings.getXmlSchemaTypes();
    if (sTypes != null) {
      xmlSchemaTypes=sTypes.getXmlSchemaType();
    }
 else {
      xmlSchemaTypes=new ArrayList<XmlSchemaType>();
    }
    if (xmlBindings.getXmlSchemaType() != null) {
      xmlSchemaTypes.add(xmlBindings.getXmlSchemaType());
    }
    for (    XmlSchemaType sType : xmlSchemaTypes) {
      JavaClass jClass=aProcessor.getHelper().getJavaClass(sType.getType());
      if (jClass != null) {
        aProcessor.processSchemaType(sType.getName(),sType.getNamespace(),jClass.getQualifiedName());
      }
    }
    nsInfo=annotationsProcessor.getPackageToNamespaceMappings().get(packageName);
    JavaTypes jTypes=xmlBindings.getJavaTypes();
    if (jTypes != null) {
      for (      JavaType javaType : jTypes.getJavaType()) {
        TypeInfo info=typeInfoMap.get(javaType.getName());
        if (javaType.getXmlJavaTypeAdapter() != null) {
          info.setXmlJavaTypeAdapter(javaType.getXmlJavaTypeAdapter());
        }
        if (javaType.isSetXmlAccessorOrder()) {
          info.setXmlAccessOrder(javaType.getXmlAccessorOrder());
        }
 else         if (!info.isSetXmlAccessOrder()) {
          if (xmlBindings.isSetXmlAccessorOrder()) {
            info.setXmlAccessOrder(xmlBindings.getXmlAccessorOrder());
          }
 else {
            info.setXmlAccessOrder(nsInfo.getAccessOrder());
          }
        }
        if (javaType.isSetXmlAccessorType()) {
          info.setXmlAccessType(javaType.getXmlAccessorType());
        }
 else         if (!info.isSetXmlAccessType()) {
          if (xmlBindings.isSetXmlAccessorType()) {
            info.setXmlAccessType(xmlBindings.getXmlAccessorType());
          }
 else {
            info.setXmlAccessType(nsInfo.getAccessType());
          }
        }
        if (javaType.isSetXmlInlineBinaryData()) {
          info.setInlineBinaryData(javaType.isXmlInlineBinaryData());
        }
        if (javaType.isSetXmlTransient()) {
          info.setXmlTransient(javaType.isXmlTransient());
        }
        if (javaType.getXmlRootElement() != null) {
          info.setXmlRootElement(javaType.getXmlRootElement());
        }
        if (javaType.getXmlSeeAlso() != null && javaType.getXmlSeeAlso().size() > 0) {
          info.setXmlSeeAlso(javaType.getXmlSeeAlso());
        }
        if (javaType.getXmlType() != null) {
          info.setXmlType(javaType.getXmlType());
        }
        if (javaType.getXmlCustomizer() != null) {
          info.setXmlCustomizer(javaType.getXmlCustomizer());
        }
      }
    }
    if (xmlBindings.getXmlJavaTypeAdapters() != null) {
      Map<String,TypeInfo> typeInfos=aProcessor.getTypeInfosForPackage(packageName);
      for (      TypeInfo tInfo : typeInfos.values()) {
        List<XmlJavaTypeAdapter> adapters=xmlBindings.getXmlJavaTypeAdapters().getXmlJavaTypeAdapter();
        for (        XmlJavaTypeAdapter xja : adapters) {
          JavaClass adapterClass=jModelInput.getJavaModel().getClass(xja.getValue());
          JavaClass boundType=jModelInput.getJavaModel().getClass(xja.getType());
          if (boundType != null) {
            tInfo.addPackageLevelAdapterClass(adapterClass,boundType);
          }
        }
      }
    }
    javaClasses=annotationsProcessor.postBuildTypeInfo(javaClasses);
    annotationsProcessor.processJavaClasses(javaClasses);
    Map<String,TypeInfo> typeInfosForPackage=annotationsProcessor.getTypeInfosForPackage(packageName);
    for (    Entry<String,TypeInfo> entry : typeInfosForPackage.entrySet()) {
      TypeInfo tInfo=entry.getValue();
      if (tInfo.isEnumerationType()) {
        EnumTypeInfo etInfo=(EnumTypeInfo)tInfo;
        XmlEnum xmlEnum=xmlEnumMap.get(etInfo.getClassName());
        if (xmlEnum != null) {
          JavaClass restrictionClass=aProcessor.getHelper().getJavaClass(xmlEnum.getValue());
          if (restrictionClass == null) {
            restrictionClass=jModelInput.getJavaModel().getClass(String.class);
          }
          etInfo.setRestrictionBase(aProcessor.getSchemaTypeFor(restrictionClass));
          for (          XmlEnumValue xmlEnumValue : xmlEnum.getXmlEnumValue()) {
            etInfo.addJavaFieldToXmlEnumValuePair(true,xmlEnumValue.getJavaEnumValue(),xmlEnumValue.getValue());
          }
        }
      }
    }
    jTypes=xmlBindings.getJavaTypes();
    if (jTypes != null) {
      for (      JavaType javaType : jTypes.getJavaType()) {
        processJavaType(javaType,typeInfosForPackage.get(javaType.getName()),nsInfo);
      }
    }
    pkgToClassMap.remove(packageName);
  }
  Iterator<ArrayList<JavaClass>> classIt=pkgToClassMap.values().iterator();
  while (classIt.hasNext()) {
    ArrayList<JavaClass> jClassList=classIt.next();
    JavaClass[] jClassArray=(JavaClass[])jClassList.toArray(new JavaClass[jClassList.size()]);
    annotationsProcessor.buildNewTypeInfo(jClassArray);
    annotationsProcessor.processJavaClasses(jClassArray);
  }
  Map<String,TypeInfo> typeInfos=(Map<String,TypeInfo>)aProcessor.getTypeInfo().clone();
  for (  Entry<String,TypeInfo> entry : typeInfos.entrySet()) {
    JavaClass[] jClassArray;
    for (    Property prop : entry.getValue().getPropertyList()) {
      if (prop.isSetXmlJavaTypeAdapter()) {
        jClassArray=new JavaClass[]{prop.getActualType()};
        aProcessor.buildNewTypeInfo(jClassArray);
      }
    }
  }
  aProcessor.finalizeProperties();
  aProcessor.createElementsForTypeMappingInfo();
}