Program: 64964
Project: 64964
Buggy source:
public final Object readFrom(Class<Object> type,Type genericType,Annotation[] annotations,MediaType mediaType,MultivaluedMap<String,String> httpHeaders,InputStream entityStream) throws IOException, WebApplicationException {
  try {
    Class<?> domainClass=getDomainClass(genericType);
    JAXBContext jaxbContext=getJAXBContext(domainClass,annotations,mediaType,httpHeaders);
    Unmarshaller unmarshaller=jaxbContext.createUnmarshaller();
    unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE,MediaType.APPLICATION_JSON);
    unmarshaller.setProperty(UnmarshallerProperties.JSON_ATTRIBUTE_PREFIX,attributePrefix);
    unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT,includeRoot);
    unmarshaller.setProperty(UnmarshallerProperties.JSON_NAMESPACE_PREFIX_MAPPER,namespacePrefixMapper);
    unmarshaller.setProperty(UnmarshallerProperties.JSON_NAMESPACE_SEPARATOR,namespaceSeperator);
    if (null != valueWrapper) {
      unmarshaller.setProperty(UnmarshallerProperties.JSON_VALUE_WRAPPER,valueWrapper);
    }
    preReadFrom(type,genericType,annotations,mediaType,httpHeaders,unmarshaller);
    StreamSource jsonSource;
    Map<String,String> mediaTypeParameters=mediaType.getParameters();
    if (mediaTypeParameters.containsKey(CHARSET)) {
      String charSet=mediaTypeParameters.get(CHARSET);
      Reader entityReader=new InputStreamReader(entityStream,charSet);
      jsonSource=new StreamSource(entityReader);
    }
 else {
      jsonSource=new StreamSource(entityStream);
    }
    JAXBElement<?> jaxbElement=unmarshaller.unmarshal(jsonSource,domainClass);
    if (type.isAssignableFrom(JAXBElement.class)) {
      return jaxbElement;
    }
 else {
      Object value=jaxbElement.getValue();
      if (value instanceof ArrayList) {
        ContainerPolicy containerPolicy;
        if (type.isAssignableFrom(List.class) || type.isAssignableFrom(ArrayList.class) || type.isAssignableFrom(Collection.class)) {
          containerPolicy=new CollectionContainerPolicy(ArrayList.class);
        }
 else         if (type.isAssignableFrom(Set.class)) {
          containerPolicy=new CollectionContainerPolicy(HashSet.class);
        }
 else         if (type.isAssignableFrom(Deque.class) || type.isAssignableFrom(Queue.class)) {
          containerPolicy=new CollectionContainerPolicy(LinkedList.class);
        }
 else         if (type.isAssignableFrom(NavigableSet.class) || type.isAssignableFrom(SortedSet.class)) {
          containerPolicy=new CollectionContainerPolicy(TreeSet.class);
        }
 else {
          containerPolicy=new CollectionContainerPolicy(type);
        }
        Object container=containerPolicy.containerInstance();
        boolean wrapItemInJAXBElement=false;
        if (genericType instanceof ParameterizedType) {
          Type actualType=((ParameterizedType)genericType).getActualTypeArguments()[0];
          if (actualType instanceof ParameterizedType) {
            Type rawType=((ParameterizedType)actualType).getRawType();
            wrapItemInJAXBElement=rawType == JAXBElement.class;
          }
        }
        for (        JAXBElement element : (Collection<JAXBElement>)value) {
          if (wrapItemInJAXBElement) {
            containerPolicy.addInto(element,container,null);
          }
 else {
            containerPolicy.addInto(element.getValue(),container,null);
          }
        }
        return container;
      }
 else {
        return value;
      }
    }
  }
 catch (  JAXBException jaxbException) {
    throw new WebApplicationException(jaxbException);
  }
}

Fixed version (ground truth):
public final Object readFrom(Class<Object> type,Type genericType,Annotation[] annotations,MediaType mediaType,MultivaluedMap<String,String> httpHeaders,InputStream entityStream) throws IOException, WebApplicationException {
  try {
    Class<?> domainClass=getDomainClass(genericType);
    JAXBContext jaxbContext=getJAXBContext(domainClass,annotations,mediaType,httpHeaders);
    Unmarshaller unmarshaller=jaxbContext.createUnmarshaller();
    unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE,MediaType.APPLICATION_JSON);
    unmarshaller.setProperty(UnmarshallerProperties.JSON_ATTRIBUTE_PREFIX,attributePrefix);
    unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT,includeRoot);
    unmarshaller.setProperty(UnmarshallerProperties.JSON_NAMESPACE_PREFIX_MAPPER,namespacePrefixMapper);
    unmarshaller.setProperty(UnmarshallerProperties.JSON_NAMESPACE_SEPARATOR,namespaceSeperator);
    if (null != valueWrapper) {
      unmarshaller.setProperty(UnmarshallerProperties.JSON_VALUE_WRAPPER,valueWrapper);
    }
    preReadFrom(type,genericType,annotations,mediaType,httpHeaders,unmarshaller);
    StreamSource jsonSource;
    Map<String,String> mediaTypeParameters=mediaType.getParameters();
    if (mediaTypeParameters.containsKey(CHARSET)) {
      String charSet=mediaTypeParameters.get(CHARSET);
      Reader entityReader=new InputStreamReader(entityStream,charSet);
      jsonSource=new StreamSource(entityReader);
    }
 else {
      jsonSource=new StreamSource(entityStream);
    }
    JAXBElement<?> jaxbElement=unmarshaller.unmarshal(jsonSource,domainClass);
    if (type.isAssignableFrom(JAXBElement.class)) {
      return jaxbElement;
    }
 else {
      Object value=jaxbElement.getValue();
      if (value instanceof ArrayList) {
        if (type.isArray()) {
          ArrayList<JAXBElement> arrayList=(ArrayList<JAXBElement>)value;
          int arrayListSize=arrayList.size();
          Object array=Array.newInstance(domainClass,arrayListSize);
          for (int x=0; x < arrayListSize; x++) {
            Array.set(array,x,arrayList.get(x).getValue());
          }
          return array;
        }
 else {
          ContainerPolicy containerPolicy;
          if (type.isAssignableFrom(List.class) || type.isAssignableFrom(ArrayList.class) || type.isAssignableFrom(Collection.class)) {
            containerPolicy=new CollectionContainerPolicy(ArrayList.class);
          }
 else           if (type.isAssignableFrom(Set.class)) {
            containerPolicy=new CollectionContainerPolicy(HashSet.class);
          }
 else           if (type.isAssignableFrom(Deque.class) || type.isAssignableFrom(Queue.class)) {
            containerPolicy=new CollectionContainerPolicy(LinkedList.class);
          }
 else           if (type.isAssignableFrom(NavigableSet.class) || type.isAssignableFrom(SortedSet.class)) {
            containerPolicy=new CollectionContainerPolicy(TreeSet.class);
          }
 else {
            containerPolicy=new CollectionContainerPolicy(type);
          }
          Object container=containerPolicy.containerInstance();
          boolean wrapItemInJAXBElement=false;
          if (genericType instanceof ParameterizedType) {
            Type actualType=((ParameterizedType)genericType).getActualTypeArguments()[0];
            if (actualType instanceof ParameterizedType) {
              Type rawType=((ParameterizedType)actualType).getRawType();
              wrapItemInJAXBElement=rawType == JAXBElement.class;
            }
          }
          for (          JAXBElement element : (Collection<JAXBElement>)value) {
            if (wrapItemInJAXBElement) {
              containerPolicy.addInto(element,container,null);
            }
 else {
              containerPolicy.addInto(element.getValue(),container,null);
            }
          }
          return container;
        }
      }
 else {
        return value;
      }
    }
  }
 catch (  JAXBException jaxbException) {
    throw new WebApplicationException(jaxbException);
  }
}