[Demonstration 1]

[Buggy Method]
public Template handleRequest(HttpServletRequest request, HttpServletResponse response, Context ctx) {
    java.sql.Connection conn = null;
    java.sql.PreparedStatement ps = null;
    java.sql.PreparedStatement ps1 = null;
    java.sql.PreparedStatement ps2 = null;
    String sqluserName = "team152";
    String sqlpassword = "b042ba74";
    String url = "jdbc:mysql://stusql.dcs.shef.ac.uk/team152";
    Template form = null;
    int ID = 0;
    String summary = request.getParameter("summary");
    String articleIdF;
    String articleId = request.getParameter("aId");
    if (articleId != null) {
        articleIdF = request.getParameter("aId");
        ctx.put("articleIdF", articleIdF);
    } else {
        articleIdF = request.getParameter("articleIdF");
    }
    HttpSession session = request.getSession(true);
    String email = (String) session.getAttribute("email");
    // if email=null the user try to access the page directly this will redicate him to an error page
    if (session.getAttribute("email") != null) {
        User user = new User(email);
        ID = user.getID();
        ctx.put("articleIdF", articleIdF);
        try {
            String articleReviewerId = "";
            Class.forName("com.mysql.jdbc.Driver").newInstance();
            conn = DriverManager.getConnection(url, sqluserName, sqlpassword);
            // prepare statement for selection,  count number of record that have the same userId and article ID ..
            ps = conn.prepareStatement("SELECT COUNT(*) , ArticleReviewerId FROM ArticleReviewer WHERE ArticleReviewer.UserId = ? AND ArticleId = ?;");
            ps.setInt(1, ID);
            ps.setString(2, articleIdF);
            ResultSet results = ps.executeQuery();
            int re = 0;
            while (results.next()) {
                re = Integer.valueOf(results.getString("COUNT(*)"));
                articleReviewerId = results.getString("ArticleReviewerId");
            }
            // if count is 0 the user try to access a doucument he did not chose to review
            if (re < 1) {
                ctx.put("ErrorMessage", "No review found in submission data");
                ctx.put("ErrorLink", "index.html");
                form = getTemplate("../../Error.vm");
                return form;
            } else {
                ps = conn.prepareStatement("SELECT Title FROM Article WHERE ArticleId = ?;");
                ps.setString(1, articleIdF);
                results = ps.executeQuery();
                while (results.next()) {
                    ctx.put("title", results.getString("Title"));
                }
                // user add the review to the form and submit
                if (summary != null) {
                    String articleReviewId = "";
                    String otherErrors = request.getParameter("otherErrors");
                    String secretComment = request.getParameter("secretComment");
                    String judgement = request.getParameter("judgement");
                    String reviewerExpertiseLevel = request.getParameter("reviewerExpertiseLevel");
                    ctx.put("status", "Please fill in the fields below. The fields marked * are mandatory.");
                    try {
                        Date date = new Date();
                        SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
                        // prepare statement for inserting the review to the ArticleReview table in DB
                        ps = conn.prepareStatement("INSERT INTO ArticleReview(ArticleReviewerId, SubmitDate,Summary,Judgement,ReviewerExpertiseLevel,OtherErrors,SecretComment) VALUES (?, ?, ?, ?, ?, ?, ?)");
                        ps.setString(1, articleReviewerId);
                        ps.setString(2, ft.format(date));
                        ps.setString(3, summary);
                        ps.setString(4, judgement);
                        ps.setString(5, reviewerExpertiseLevel);
                        ps.setString(6, otherErrors);
                        ps.setString(7, secretComment);
                        ps.executeUpdate();
                        //select that review id
                        ps = conn.prepareStatement("SELECT ArticleReviewId FROM ArticleReview WHERE ArticleReviewerId = ? AND SubmitDate = ?;");
                        ps.setString(1, articleReviewerId);
                        ps.setString(2, ft.format(date));
                        results = ps.executeQuery();
                        while (results.next()) {
                            articleReviewId = results.getString("ArticleReviewId");
                        }
                        Enumeration attrs = request.getParameterNames();
                        while (attrs.hasMoreElements()) {
                            String element = (String) attrs.nextElement();
                            if (element.startsWith("criticism.")) {
                                // prepare statement for inserting all the Criticisms to the Criticism table in DB
                                ps = conn.prepareStatement("INSERT INTO Criticism (ArticleReviewId, CriticismBody) VALUES (?,?);");
                                ps.setString(1, articleReviewerId);
                                ps.setString(2, request.getParameter(element));
                                ps.executeUpdate();
                            }
                        }
                        ps = conn.prepareStatement("UPDATE ArticleReviewer SET Status='3' WHERE ArticleReviewerId=?;");
                        ps.setString(1, articleReviewerId);
                        ps.executeUpdate();
                    } catch (SQLException e) {
                        conn.close();
                        ctx.put("ErrorMessage", e);
                        ctx.put("ErrorLink", "index.html");
                        form = getTemplate("../../Error.vm");
                        return form;
                    } finally {
                        try {
                            conn.close();
                            request.setAttribute("ReviewID", articleReviewId);
                            request.getRequestDispatcher("ReviewSubmitSuccess").forward(request, response);
                        } catch (SQLException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        } catch (Exception e) {
            ctx.put("status", " A technical problem occured while trying to submit please try submitting again.");
            System.out.println(" A technical problem:" + e);
        } finally {
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        try {
            form = getTemplate("../../SubmitReview.vm");
        } catch (Exception e) {
            System.out.println("Submit excpetion: " + e);
        }
    } else //to stop the direct access
    {
        ctx.put("ErrorMessage", "No Login Found");
        ctx.put("ErrorLink", "index.html");
        form = getTemplate("../../Error.vm");
        return form;
    }
    return form;
}

[Buggy Hunk]
ps.setString(1, articleReviewerId);

[Patch]
ps.setString(1, articleReviewId);

[Demonstration 2]

[Buggy Method]
String sendRequest(String commandline) throws IOException {
    ByteBuffer writeBuffer = wrapCommandToBuffer(commandline);
    while (writeBuffer.hasRemaining()) {
        clientSocket.write(writeBuffer);
    }
    ByteBuffer readBuffer = ByteBuffer.allocate(1024);
    if (clientSocket.read(readBuffer) == -1) {
        throw new IOException();
    }
    readBuffer.flip();
    return new String(readBuffer.array()).trim();
}

[Buggy Hunk]
String sendRequest(String commandline) throws IOException {

[Patch]
public String sendRequest(String commandline) throws IOException {

[Demonstration 3]

[Buggy Method]
@ExceptionHandler(HttpMessageNotReadableException.class)
public ResponseEntity<ErrorDto> handle(HttpMessageNotReadableException e) {
    LOGGER.warn("{}", e.getMessage());
    return buildResponse(HttpStatus.BAD_REQUEST, e.getMessage());
}

[Buggy Hunk]
return buildResponse(HttpStatus.BAD_REQUEST, e.getMessage());

[Patch]
return buildResponse(HttpStatus.BAD_REQUEST, "Invalid json");