Program: 63656
Project: 63656
Buggy source:
public Object readFrom(Class<Object> type,Type genericType,Annotation[] annotations,MediaType mediaType,MultivaluedMap<String,String> httpHeaders,InputStream entityStream) throws IOException, WebApplicationException {
  try {
    if (null == genericType) {
      genericType=type;
    }
    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);
    }
    unmarshaller.setProperty(UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME,wrapperAsArrayName);
    preReadFrom(type,genericType,annotations,mediaType,httpHeaders,unmarshaller);
    StreamSource jsonSource;
    Map<String,String> mediaTypeParameters=null;
    if (null != mediaType) {
      mediaTypeParameters=mediaType.getParameters();
    }
    if (null != mediaTypeParameters && 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<Object> arrayList=(ArrayList<Object>)value;
          int arrayListSize=arrayList.size();
          boolean wrapItemInJAXBElement=wrapItemInJAXBElement(genericType);
          Object array;
          if (wrapItemInJAXBElement) {
            array=Array.newInstance(JAXBElement.class,arrayListSize);
          }
 else {
            array=Array.newInstance(domainClass,arrayListSize);
          }
          for (int x=0; x < arrayListSize; x++) {
            Object element=handleJAXBElement(arrayList.get(x),domainClass,wrapItemInJAXBElement);
            Array.set(array,x,element);
          }
          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=wrapItemInJAXBElement(genericType);
          for (          Object element : (Collection<Object>)value) {
            element=handleJAXBElement(element,domainClass,wrapItemInJAXBElement);
            containerPolicy.addInto(element,container,null);
          }
          return container;
        }
      }
 else {
        return value;
      }
    }
  }
 catch (  UnmarshalException unmarshalException) {
    ResponseBuilder builder=Response.status(Status.BAD_REQUEST);
    throw new WebApplicationException(builder.build());
  }
catch (  JAXBException jaxbException) {
    throw new WebApplicationException(jaxbException);
  }
}

Fixed version (ground truth):
public Object readFrom(Class<Object> type,Type genericType,Annotation[] annotations,MediaType mediaType,MultivaluedMap<String,String> httpHeaders,InputStream entityStream) throws IOException, WebApplicationException {
  try {
    if (null == genericType) {
      genericType=type;
    }
    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);
    }
    unmarshaller.setProperty(UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME,wrapperAsArrayName);
    preReadFrom(type,genericType,annotations,mediaType,httpHeaders,unmarshaller);
    StreamSource jsonSource;
    Map<String,String> mediaTypeParameters=null;
    if (null != mediaType) {
      mediaTypeParameters=mediaType.getParameters();
    }
    if (null != mediaTypeParameters && 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<Object> arrayList=(ArrayList<Object>)value;
          int arrayListSize=arrayList.size();
          boolean wrapItemInJAXBElement=wrapItemInJAXBElement(genericType);
          Object array;
          if (wrapItemInJAXBElement) {
            array=Array.newInstance(JAXBElement.class,arrayListSize);
          }
 else {
            array=Array.newInstance(domainClass,arrayListSize);
          }
          for (int x=0; x < arrayListSize; x++) {
            Object element=handleJAXBElement(arrayList.get(x),domainClass,wrapItemInJAXBElement);
            Array.set(array,x,element);
          }
          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=wrapItemInJAXBElement(genericType);
          for (          Object element : (Collection<Object>)value) {
            element=handleJAXBElement(element,domainClass,wrapItemInJAXBElement);
            containerPolicy.addInto(element,container,null);
          }
          return container;
        }
      }
 else {
        return value;
      }
    }
  }
 catch (  UnmarshalException unmarshalException) {
    ResponseBuilder builder=Response.status(Status.BAD_REQUEST);
    throw new WebApplicationException(unmarshalException,builder.build());
  }
catch (  JAXBException jaxbException) {
    throw new WebApplicationException(jaxbException);
  }
}