[Demonstration 1]

[Buggy Method]
public <T> HttpClientResponse<T> execute(HttpMethod httpMethod, HttpClientCallback<T> callback) throws IOException, HttpException {
    String resultCode = "";
    HttpTracer httpTracer = null;
    try {
        // 1、从工厂获取HttpTracer
        httpTracer = TracerFactory.getHttpClientTracer();
        // 2、开始Http请求,调用startInvoke
        HttpContext httpContext = httpTracer.startInvoke();
        // 3、将上下文中Tracer参数设置到请求头
        if (httpContext != null) {
            if (httpMethod instanceof PostMethod) {
                ((PostMethod) httpMethod).addParameter("qid", httpContext.getTraceId());
            } else if (httpMethod instanceof GetMethod) {
                String url = httpMethod.getURI().getURI();
                if (url.indexOf("?") != -1) {
                    url = url + "&qid=" + httpContext.getTraceId();
                } else {
                    url = url + "?qid=" + httpContext.getTraceId();
                }
                httpMethod.setURI(new URI(url, true, httpMethod.getParams().getUriCharset()));
            }
            httpContext.setUrl(httpMethod.getURI().getURI());
            httpContext.setMethod(httpMethod.getName());
            httpContext.setCurrentApp(appName);
            if (httpMethod instanceof EntityEnclosingMethod) {
                RequestEntity requestEntity = ((EntityEnclosingMethod) httpMethod).getRequestEntity();
                if (requestEntity != null) {
                    httpContext.setRequestSize(requestEntity.getContentLength());
                }
            }
        }
        // 4、开始Http请求,调用executeMethod
        int httpCode = httpClient.executeMethod(httpMethod);
        // 5、将Http请求结果设置到上下文中
        if (httpContext != null) {
            resultCode = String.valueOf(httpCode);
            if (httpMethod instanceof HttpMethodBase) {
                HttpMethodBase httpMethodBase = (HttpMethodBase) httpMethod;
                httpContext.setResponseSize(httpMethodBase.getResponseContentLength());
            }
        }
        // 6、调用CallBack处理Http请求返回结果
        return callback.process(httpMethod);
    } finally {
        // 7、结束Http请求调用，打印Trace日志
        if (httpTracer != null) {
            httpTracer.finishInvoke(resultCode, HttpContext.class);
        }
        // 8、释放Http请求链接
        httpMethod.releaseConnection();
    }
}

[Buggy Hunk]
String url = httpMethod.getURI().getURI();

[Patch]
String url = httpMethod.getURI().getEscapedURI();

[Demonstration 2]

[Buggy Method]
private void loadChatHistory(Context context) {
    chatHistory = new ArrayList<ChatMessage>();
    datasource = new ChatDataSource(context);
    ConversationDataSource conversationDataSource = new ConversationDataSource(context);
    conversationDataSource.open();
    WnConversation conversation = conversationDataSource.getConversationByID(c_id);
    conversation_id = conversation.getConversation_id();
    conversationDataSource.close();
    datasource.open();
    Cursor cursor = datasource.getAllDataByConversationRowID(c_id);
    int cursorCount = cursor.getCount();
    cursor.moveToFirst();
    //SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss");
    for (chatMessageID = 1; chatMessageID <= cursorCount; chatMessageID++) {
        ChatMessage msg = new ChatMessage();
        msg.setId(chatMessageID);
        msg.setMe(cursor.getString(4).equals(myPhone));
        msg.setMessage(cursor.getString(3));
        //msg.setDate(DateFormat.getDateTimeInstance().format(cursor.getString(1)));
        msg.setDate(cursor.getString(1));
        chatHistory.add(msg);
        cursor.moveToNext();
    }
    cursor.close();
    adapter = new ChatAdapter(getActivity(), new ArrayList<ChatMessage>());
    messagesContainer.setAdapter(adapter);
    for (int i = 0; i < chatHistory.size(); i++) {
        ChatMessage message = chatHistory.get(i);
        displayMessage(message);
    }
}

[Buggy Hunk]
private void loadChatHistory(Context context){

[Patch]
public void loadChatHistory(Context context){

[Demonstration 3]

[Buggy Method]
private void employeeAddDiscount(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    try {
        int idOrder = Integer.parseInt(request.getParameter("idOrder"));
        double discountRate = Double.parseDouble(request.getParameter("discountRate"));
        if (discountRate > 100) {
            request.setAttribute("Error", "IncorrectDiscountOrOrderId");
            request.getRequestDispatcher("employeeOverview.jsp").forward(request, response);
            return;
        }
        try {
            OrderFacade.setDiscountRate(discountRate, idOrder);
        } catch (StorageLayerException e) {
            request.getRequestDispatcher("error.jsp").forward(request, response);
        }
        request.getRequestDispatcher("employeeOverview.jsp").forward(request, response);
    } catch (InvalidOrderIdException | NumberFormatException e) {
        request.setAttribute("Error", "IncorrectDiscountOrOrderId");
        request.getRequestDispatcher("employeeOverview.jsp").forward(request, response);
    }
}

[Buggy Hunk]
if (discountRate > 100) {

[Patch]
if (discountRate > 100 || discountRate < 0) {