Program: 66049
Project: 66049
Buggy source:
/** 
 * Create an instance of XMLRoot populated from the contents of the provided JAXBElement. XMLRoot will be used to hold the contents of the JAXBElement while the marshal operation is performed by TopLink OXM. This will avoid adding any runtime dependencies to TopLink.
 * @param elt
 * @return
 */
private XMLRoot createXMLRootFromJAXBElement(JAXBElement elt){
  XMLRoot xmlroot=new XMLRoot();
  Object objectValue=elt.getValue();
  xmlroot.setObject(objectValue);
  QName qname=elt.getName();
  xmlroot.setLocalName(qname.getLocalPart());
  xmlroot.setNamespaceURI(qname.getNamespaceURI());
  xmlroot.setDeclaredType(elt.getDeclaredType());
  xmlroot.setNil(elt.isNil());
  if (elt.getDeclaredType() == ClassConstants.ABYTE || elt.getDeclaredType() == ClassConstants.APBYTE || elt.getDeclaredType().getCanonicalName().equals("String_Node_Str")) {
    xmlroot.setSchemaType(XMLConstants.BASE_64_BINARY_QNAME);
    Class generatedClass=getClassToGeneratedClasses().get(elt.getDeclaredType().getCanonicalName());
    if (generatedClass != null && WrappedValue.class.isAssignableFrom(generatedClass)) {
      ClassDescriptor desc=xmlMarshaller.getXMLContext().getSession(generatedClass).getDescriptor(generatedClass);
      Object newObject=desc.getInstantiationPolicy().buildNewInstance();
      ((WrappedValue)newObject).setValue(objectValue);
      xmlroot.setObject(newObject);
      return xmlroot;
    }
  }
 else {
    xmlroot.setSchemaType((QName)org.eclipse.persistence.internal.oxm.XMLConversionManager.getDefaultJavaTypes().get(elt.getDeclaredType()));
  }
  if (elt instanceof WrappedValue) {
    xmlroot.setObject(elt);
    return xmlroot;
  }
  if (qNameToGeneratedClasses != null) {
    Class theClass=qNameToGeneratedClasses.get(qname);
    if (theClass != null && WrappedValue.class.isAssignableFrom(theClass)) {
      ClassDescriptor desc=xmlMarshaller.getXMLContext().getSession(theClass).getDescriptor(theClass);
      Object newObject=desc.getInstantiationPolicy().buildNewInstance();
      ((WrappedValue)newObject).setValue(objectValue);
      xmlroot.setObject(newObject);
      return xmlroot;
    }
  }
  Class generatedClass=null;
  if (jaxbContext.getTypeMappingInfoToGeneratedType() != null) {
    if (elt.getDeclaredType() != null && elt.getDeclaredType().isArray()) {
      TypeMappingInfo tmi=jaxbContext.getTypeToTypeMappingInfo().get(elt.getDeclaredType());
      generatedClass=jaxbContext.getTypeMappingInfoToGeneratedType().get(tmi);
    }
 else     if (elt instanceof JAXBTypeElement) {
      Type objectType=((JAXBTypeElement)elt).getType();
      TypeMappingInfo tmi=jaxbContext.getTypeToTypeMappingInfo().get(objectType);
      generatedClass=jaxbContext.getTypeMappingInfoToGeneratedType().get(tmi);
    }
  }
 else {
    if (elt.getDeclaredType() != null && elt.getDeclaredType().isArray()) {
      if (jaxbContext.getArrayClassesToGeneratedClasses() != null) {
        generatedClass=jaxbContext.getArrayClassesToGeneratedClasses().get(elt.getDeclaredType().getCanonicalName());
      }
    }
 else     if (elt instanceof JAXBTypeElement) {
      Type objectType=((JAXBTypeElement)elt).getType();
      generatedClass=jaxbContext.getCollectionClassesToGeneratedClasses().get(objectType);
    }
  }
  if (generatedClass != null) {
    ClassDescriptor desc=xmlMarshaller.getXMLContext().getSession(generatedClass).getDescriptor(generatedClass);
    Object newObject=desc.getInstantiationPolicy().buildNewInstance();
    ((ManyValue)newObject).setItem(objectValue);
    xmlroot.setObject(newObject);
  }
  return xmlroot;
}

Fixed version (ground truth):
/** 
 * Create an instance of XMLRoot populated from the contents of the provided JAXBElement. XMLRoot will be used to hold the contents of the JAXBElement while the marshal operation is performed by TopLink OXM. This will avoid adding any runtime dependencies to TopLink.
 * @param elt
 * @return
 */
private XMLRoot createXMLRootFromJAXBElement(JAXBElement elt){
  XMLRoot xmlroot=new XMLRoot();
  Object objectValue=elt.getValue();
  xmlroot.setObject(objectValue);
  QName qname=elt.getName();
  xmlroot.setLocalName(qname.getLocalPart());
  xmlroot.setNamespaceURI(qname.getNamespaceURI());
  xmlroot.setDeclaredType(elt.getDeclaredType());
  xmlroot.setNil(elt.isNil());
  if (elt.getDeclaredType() == ClassConstants.ABYTE || elt.getDeclaredType() == ClassConstants.APBYTE || elt.getDeclaredType().getCanonicalName().equals("String_Node_Str")) {
    xmlroot.setSchemaType(XMLConstants.BASE_64_BINARY_QNAME);
    Class generatedClass=getClassToGeneratedClasses().get(elt.getDeclaredType().getCanonicalName());
    if (generatedClass != null && WrappedValue.class.isAssignableFrom(generatedClass)) {
      ClassDescriptor desc=xmlMarshaller.getXMLContext().getSession(generatedClass).getDescriptor(generatedClass);
      Object newObject=desc.getInstantiationPolicy().buildNewInstance();
      ((WrappedValue)newObject).setValue(objectValue);
      xmlroot.setObject(newObject);
      return xmlroot;
    }
  }
 else {
    xmlroot.setSchemaType((QName)org.eclipse.persistence.internal.oxm.XMLConversionManager.getDefaultJavaTypes().get(elt.getDeclaredType()));
  }
  if (elt instanceof WrappedValue) {
    xmlroot.setObject(elt);
    return xmlroot;
  }
  if (qNameToGeneratedClasses != null) {
    Class theClass=qNameToGeneratedClasses.get(qname);
    if (theClass != null && WrappedValue.class.isAssignableFrom(theClass)) {
      ClassDescriptor desc=xmlMarshaller.getXMLContext().getSession(theClass).getDescriptor(theClass);
      Object newObject=desc.getInstantiationPolicy().buildNewInstance();
      ((WrappedValue)newObject).setValue(objectValue);
      xmlroot.setObject(newObject);
      return xmlroot;
    }
  }
  Class generatedClass=null;
  if (jaxbContext.getTypeMappingInfoToGeneratedType() != null) {
    if (jaxbContext.getTypeToTypeMappingInfo() != null) {
      if (elt.getDeclaredType() != null && elt.getDeclaredType().isArray()) {
        TypeMappingInfo tmi=jaxbContext.getTypeToTypeMappingInfo().get(elt.getDeclaredType());
        generatedClass=jaxbContext.getTypeMappingInfoToGeneratedType().get(tmi);
      }
 else       if (elt instanceof JAXBTypeElement) {
        Type objectType=((JAXBTypeElement)elt).getType();
        TypeMappingInfo tmi=jaxbContext.getTypeToTypeMappingInfo().get(objectType);
        generatedClass=jaxbContext.getTypeMappingInfoToGeneratedType().get(tmi);
      }
    }
  }
 else {
    if (elt.getDeclaredType() != null && elt.getDeclaredType().isArray()) {
      if (jaxbContext.getArrayClassesToGeneratedClasses() != null) {
        generatedClass=jaxbContext.getArrayClassesToGeneratedClasses().get(elt.getDeclaredType().getCanonicalName());
      }
    }
 else     if (elt instanceof JAXBTypeElement) {
      Type objectType=((JAXBTypeElement)elt).getType();
      generatedClass=jaxbContext.getCollectionClassesToGeneratedClasses().get(objectType);
    }
  }
  if (generatedClass != null) {
    ClassDescriptor desc=xmlMarshaller.getXMLContext().getSession(generatedClass).getDescriptor(generatedClass);
    Object newObject=desc.getInstantiationPolicy().buildNewInstance();
    ((ManyValue)newObject).setItem(objectValue);
    xmlroot.setObject(newObject);
  }
  return xmlroot;
}