Program: 65692
Project: 65692
Buggy source:
/** 
 * Process XmlBindings on a per package basis for a given AnnotationsProcessor 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());
      }
    }
    PackageInfo packageInfo=annotationsProcessor.getPackageToPackageInfoMappings().get(packageName);
    if (packageInfo == null) {
      packageInfo=new PackageInfo();
    }
    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());
        }
        String transformerClassName=javaType.getXmlNameTransformer();
        XMLNameTransformer transformer=getXMLNameTransformerClassFromString(transformerClassName);
        if (transformer != null) {
          info.setXmlNameTransformer(transformer);
        }
        if (javaType.getXmlVirtualAccessMethods() != null) {
          info.setXmlVirtualAccessMethods(javaType.getXmlVirtualAccessMethods());
        }
        if (javaType.isSetXmlAccessorOrder()) {
          info.setXmlAccessOrder(javaType.getXmlAccessorOrder());
        }
 else         if (!info.isSetXmlAccessOrder()) {
          if (xmlBindings.isSetXmlAccessorOrder()) {
            info.setXmlAccessOrder(xmlBindings.getXmlAccessorOrder());
          }
 else {
            info.setXmlAccessOrder(packageInfo.getAccessOrder());
          }
        }
        if (javaType.isSetXmlAccessorType()) {
          info.setXmlAccessType(javaType.getXmlAccessorType());
        }
 else         if (!info.isSetXmlAccessType()) {
          if (xmlBindings.isSetXmlAccessorType()) {
            info.setXmlAccessType(xmlBindings.getXmlAccessorType());
          }
 else {
            info.setXmlAccessType(packageInfo.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 (javaType.getXmlClassExtractor() != null) {
          info.setClassExtractorName(javaType.getXmlClassExtractor().getClazz());
        }
        if (javaType.getXmlProperties() != null && javaType.getXmlProperties().getXmlProperty().size() > 0) {
          if (info.getUserProperties() != null) {
            info.setUserProperties(mergeUserPropertyMap(javaType.getXmlProperties().getXmlProperty(),info.getUserProperties()));
          }
 else {
            info.setUserProperties(createUserPropertyMap(javaType.getXmlProperties().getXmlProperty()));
          }
        }
        if (javaType.getXmlDiscriminatorNode() != null) {
          info.setXmlDiscriminatorNode(javaType.getXmlDiscriminatorNode());
        }
        if (javaType.getXmlDiscriminatorValue() != null) {
          info.setXmlDiscriminatorValue(javaType.getXmlDiscriminatorValue());
        }
      }
    }
    Map<String,TypeInfo> typeInfos=aProcessor.getTypeInfosForPackage(packageName);
    String transformerClassName=xmlBindings.getXmlNameTransformer();
    XMLNameTransformer transformer=getXMLNameTransformerClassFromString(transformerClassName);
    if (transformer != null) {
      packageInfo.setXmlNameTransformer(transformer);
    }
    for (    TypeInfo tInfo : typeInfos.values()) {
      if (xmlBindings.getXmlJavaTypeAdapters() != null) {
        List<XmlJavaTypeAdapter> adapters=xmlBindings.getXmlJavaTypeAdapters().getXmlJavaTypeAdapter();
        for (        XmlJavaTypeAdapter xja : adapters) {
          try {
            JavaClass adapterClass=jModelInput.getJavaModel().getClass(xja.getValue());
            JavaClass boundType=jModelInput.getJavaModel().getClass(xja.getType());
            if (boundType != null) {
              tInfo.addPackageLevelAdapterClass(adapterClass,boundType);
              packageInfo.getPackageLevelAdaptersByClass().put(boundType.getQualifiedName(),adapterClass);
            }
          }
 catch (          JAXBException e) {
            throw JAXBException.invalidPackageAdapterClass(xja.getValue(),packageName);
          }
        }
      }
    }
  }
  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);
    JavaClass[] javaClasses=(JavaClass[])classesToProcess.toArray(new JavaClass[classesToProcess.size()]);
    javaClasses=annotationsProcessor.postBuildTypeInfo(javaClasses);
    annotationsProcessor.processJavaClasses(null);
    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());
          }
        }
      }
    }
    JavaTypes jTypes=xmlBindings.getJavaTypes();
    if (jTypes != null) {
      NamespaceInfo nsInfo=annotationsProcessor.getPackageToPackageInfoMappings().get(packageName).getNamespaceInfo();
      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);
      }
    }
  }
  ArrayList<JavaClass> jClasses=aProcessor.getTypeInfoClasses();
  aProcessor.processPropertyTypes(jClasses.toArray(new JavaClass[jClasses.size()]));
  aProcessor.finalizeProperties();
  aProcessor.createElementsForTypeMappingInfo();
}

Fixed version (ground truth):
/** 
 * Process XmlBindings on a per package basis for a given AnnotationsProcessor 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());
      }
    }
    PackageInfo packageInfo=annotationsProcessor.getPackageToPackageInfoMappings().get(packageName);
    if (packageInfo == null) {
      packageInfo=new PackageInfo();
    }
    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());
        }
        String transformerClassName=javaType.getXmlNameTransformer();
        XMLNameTransformer transformer=getXMLNameTransformerClassFromString(transformerClassName);
        if (transformer != null) {
          info.setXmlNameTransformer(transformer);
        }
        if (javaType.getXmlVirtualAccessMethods() != null) {
          info.setXmlVirtualAccessMethods(javaType.getXmlVirtualAccessMethods());
        }
        if (javaType.isSetXmlAccessorOrder()) {
          info.setXmlAccessOrder(javaType.getXmlAccessorOrder());
        }
 else         if (!info.isSetXmlAccessOrder()) {
          if (xmlBindings.isSetXmlAccessorOrder()) {
            info.setXmlAccessOrder(xmlBindings.getXmlAccessorOrder());
          }
 else {
            info.setXmlAccessOrder(packageInfo.getAccessOrder());
          }
        }
        if (javaType.isSetXmlAccessorType()) {
          info.setXmlAccessType(javaType.getXmlAccessorType());
        }
 else         if (!info.isSetXmlAccessType()) {
          if (xmlBindings.isSetXmlAccessorType()) {
            info.setXmlAccessType(xmlBindings.getXmlAccessorType());
          }
 else {
            info.setXmlAccessType(packageInfo.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 (javaType.getXmlClassExtractor() != null) {
          info.setClassExtractorName(javaType.getXmlClassExtractor().getClazz());
        }
        if (javaType.getXmlProperties() != null && javaType.getXmlProperties().getXmlProperty().size() > 0) {
          if (info.getUserProperties() != null) {
            info.setUserProperties(mergeUserPropertyMap(javaType.getXmlProperties().getXmlProperty(),info.getUserProperties()));
          }
 else {
            info.setUserProperties(createUserPropertyMap(javaType.getXmlProperties().getXmlProperty()));
          }
        }
        if (javaType.getXmlDiscriminatorNode() != null) {
          info.setXmlDiscriminatorNode(javaType.getXmlDiscriminatorNode());
        }
        if (javaType.getXmlDiscriminatorValue() != null) {
          info.setXmlDiscriminatorValue(javaType.getXmlDiscriminatorValue());
        }
      }
    }
    Map<String,TypeInfo> typeInfos=aProcessor.getTypeInfosForPackage(packageName);
    String transformerClassName=xmlBindings.getXmlNameTransformer();
    XMLNameTransformer transformer=getXMLNameTransformerClassFromString(transformerClassName);
    if (transformer != null) {
      packageInfo.setXmlNameTransformer(transformer);
    }
    for (    TypeInfo tInfo : typeInfos.values()) {
      if (xmlBindings.getXmlJavaTypeAdapters() != null) {
        List<XmlJavaTypeAdapter> adapters=xmlBindings.getXmlJavaTypeAdapters().getXmlJavaTypeAdapter();
        for (        XmlJavaTypeAdapter xja : adapters) {
          try {
            JavaClass adapterClass=jModelInput.getJavaModel().getClass(xja.getValue());
            JavaClass boundType=jModelInput.getJavaModel().getClass(xja.getType());
            if (boundType != null) {
              tInfo.addPackageLevelAdapterClass(adapterClass,boundType);
              packageInfo.getPackageLevelAdaptersByClass().put(boundType.getQualifiedName(),adapterClass);
            }
          }
 catch (          JAXBException e) {
            throw JAXBException.invalidPackageAdapterClass(xja.getValue(),packageName);
          }
        }
      }
    }
  }
  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);
    JavaClass[] javaClasses=(JavaClass[])classesToProcess.toArray(new JavaClass[classesToProcess.size()]);
    javaClasses=annotationsProcessor.postBuildTypeInfo(javaClasses);
    annotationsProcessor.processJavaClasses(null);
    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());
          }
        }
      }
    }
    JavaTypes jTypes=xmlBindings.getJavaTypes();
    if (jTypes != null) {
      PackageInfo packageInfo=annotationsProcessor.getPackageToPackageInfoMappings().get(packageName);
      NamespaceInfo nsInfo=null;
      if (null != packageInfo) {
        nsInfo=packageInfo.getNamespaceInfo();
      }
      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);
      }
    }
  }
  ArrayList<JavaClass> jClasses=aProcessor.getTypeInfoClasses();
  aProcessor.processPropertyTypes(jClasses.toArray(new JavaClass[jClasses.size()]));
  aProcessor.finalizeProperties();
  aProcessor.createElementsForTypeMappingInfo();
}