Program: 64367
Project: 64367
Buggy source:
public void write(OutputStream output) throws IOException, WebApplicationException {
  if (result instanceof byte[] && this.mediaType.equals(MediaType.APPLICATION_OCTET_STREAM_TYPE)) {
    output.write((byte[])result);
  }
 else   if (result instanceof String) {
    OutputStreamWriter writer=new OutputStreamWriter(output);
    writer.write((String)result);
    writer.flush();
    writer.close();
  }
 else   if (result instanceof QueryResultList) {
    try {
      Class<?>[] jaxbClasses=new Class[]{QueryResultList.class};
      JAXBContext context=(JAXBContext)JAXBContextFactory.createContext(jaxbClasses,null);
      JAXBContextFactory.createContext(jaxbClasses,null,QueryResultList.class.getClassLoader());
      Marshaller marshaller=context.createMarshaller();
      marshaller.setProperty(MarshallerProperties.MEDIA_TYPE,mediaType.toString());
      result=(QueryResultList)result;
      marshaller.marshal(result,output);
    }
 catch (    Exception e) {
      e.printStackTrace();
      throw new JPARSException(e.getMessage());
    }
  }
 else {
    if (this.context != null && this.context.getJAXBContext() != null && this.result != null && (this.mediaType.equals(MediaType.APPLICATION_JSON_TYPE) || this.mediaType.equals(MediaType.APPLICATION_XML_TYPE))) {
      try {
        context.marshallEntity(result,mediaType,output);
        return;
      }
 catch (      JAXBException e) {
        JAXBException initialException=e;
        if (this.result instanceof List) {
          List<JAXBElement<Object>> returnList=new ArrayList<JAXBElement<Object>>(((List)this.result).size());
          List resultAsList=(List)this.result;
          try {
            for (            Object object : resultAsList) {
              JAXBElement jaxbResult=new JAXBElement(new QName("String_Node_Str"),object.getClass(),object);
              returnList.add(jaxbResult);
            }
            context.marshallEntity(returnList,mediaType,output);
            return;
          }
 catch (          JAXBException ex) {
            JPARSLogger.fine("String_Node_Str",new Object[]{ex.toString()});
          }
        }
        JPARSLogger.fine("String_Node_Str",new Object[]{initialException});
      }
    }
    if (this.mediaType.equals(MediaType.APPLICATION_OCTET_STREAM_TYPE)) {
      ByteArrayOutputStream baos=new ByteArrayOutputStream();
      ObjectOutputStream oos=new ObjectOutputStream(baos);
      oos.writeObject(result);
      oos.flush();
      oos.close();
      output.write(baos.toByteArray());
    }
 else {
      JPARSLogger.fine("String_Node_Str",new Object[]{result});
    }
  }
}

Fixed version (ground truth):
public void write(OutputStream output) throws IOException, WebApplicationException {
  if (result instanceof byte[] && this.mediaType.equals(MediaType.APPLICATION_OCTET_STREAM_TYPE)) {
    output.write((byte[])result);
  }
 else   if (result instanceof String) {
    OutputStreamWriter writer=new OutputStreamWriter(output);
    writer.write((String)result);
    writer.flush();
    writer.close();
  }
 else   if (result instanceof QueryResultList) {
    try {
      Class<?>[] jaxbClasses=new Class[]{QueryResultList.class};
      JAXBContext context=(JAXBContext)JAXBContextFactory.createContext(jaxbClasses,null);
      JAXBContextFactory.createContext(jaxbClasses,null,QueryResultList.class.getClassLoader());
      Marshaller marshaller=context.createMarshaller();
      marshaller.setProperty(MarshallerProperties.JSON_REDUCE_ANY_ARRAYS,true);
      marshaller.setProperty(MarshallerProperties.MEDIA_TYPE,mediaType.toString());
      result=(QueryResultList)result;
      marshaller.marshal(result,output);
    }
 catch (    Exception e) {
      e.printStackTrace();
      throw new JPARSException(e.getMessage());
    }
  }
 else {
    if (this.context != null && this.context.getJAXBContext() != null && this.result != null && (this.mediaType.equals(MediaType.APPLICATION_JSON_TYPE) || this.mediaType.equals(MediaType.APPLICATION_XML_TYPE))) {
      try {
        context.marshallEntity(result,mediaType,output);
        return;
      }
 catch (      JAXBException e) {
        JAXBException initialException=e;
        if (this.result instanceof List) {
          List<JAXBElement<Object>> returnList=new ArrayList<JAXBElement<Object>>(((List)this.result).size());
          List resultAsList=(List)this.result;
          try {
            for (            Object object : resultAsList) {
              JAXBElement jaxbResult=new JAXBElement(new QName("String_Node_Str"),object.getClass(),object);
              returnList.add(jaxbResult);
            }
            context.marshallEntity(returnList,mediaType,output);
            return;
          }
 catch (          JAXBException ex) {
            JPARSLogger.fine("String_Node_Str",new Object[]{ex.toString()});
          }
        }
        JPARSLogger.fine("String_Node_Str",new Object[]{initialException});
      }
    }
    if (this.mediaType.equals(MediaType.APPLICATION_OCTET_STREAM_TYPE)) {
      ByteArrayOutputStream baos=new ByteArrayOutputStream();
      ObjectOutputStream oos=new ObjectOutputStream(baos);
      oos.writeObject(result);
      oos.flush();
      oos.close();
      output.write(baos.toByteArray());
    }
 else {
      JPARSLogger.fine("String_Node_Str",new Object[]{result});
    }
  }
}