Program: 64943
Project: 64943
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) {
        if (type.isAssignableFrom(value.getClass())) {
          return value;
        }
        ContainerPolicy containerPolicy=ContainerPolicy.buildPolicyFor(type);
        Object container=containerPolicy.containerInstance();
        for (        Object element : (Collection)value) {
          containerPolicy.addInto(element,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.isAssignableFrom(value.getClass())) {
          return value;
        }
        ContainerPolicy containerPolicy;
        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();
        for (        Object element : (Collection)value) {
          containerPolicy.addInto(element,container,null);
        }
        return container;
      }
 else {
        return value;
      }
    }
  }
 catch (  JAXBException jaxbException) {
    throw new WebApplicationException(jaxbException);
  }
}