[Demonstration 1]

[Buggy Method]
private NoteDisplacement[] computeNotes(ChordLps lps, StemDirection sd, float stemOffset) {
    NoteDisplacement[] notes = new NoteDisplacement[lps.getNotesCount()];
    //if stem direction is down or none, begin with the highest note,
    //otherwise with the lowest
    int dir = (sd == StemDirection.Up) ? 1 : -1;
    int startIndex = (dir == 1) ? 0 : lps.getNotesCount() - 1;
    int endIndex = lps.getNotesCount() - 1 - startIndex;
    //default side of the stem. 1 = right, 0 = left
    int stemSide = (sd == StemDirection.Up) ? 1 : 0;
    int lastSide = stemSide;
    for (int i = startIndex; dir * i <= dir * endIndex; i += dir) {
        int side = 1 - stemSide;
        NoteSuspension suspension = NoteSuspension.None;
        if (i == startIndex) {
            //first note: use default side
        } else {
            //following note: change side, if last note is 1 or 0 LPs away
            if (lps.get(i) - lps.get(i - dir) <= 1) {
                //change side
                side = 1 - lastSide;
                if (side != 1 - stemSide) {
                    if (side == 0)
                        suspension = NoteSuspension.Left;
                    else
                        suspension = NoteSuspension.Right;
                }
            }
        }
        notes[i] = new NoteDisplacement(lps.get(i), side * stemOffset, suspension);
        lastSide = side;
    }
    return notes;
}

[Buggy Hunk]
if (lps.get(i) - lps.get(i - dir) <= 1) {

[Patch]
if (abs(lps.get(i) - lps.get(i - dir)) <= 1) {

[Demonstration 2]

[Buggy Method]
private void forward(String target, HttpServletRequest request, HttpServletResponse response, boolean privateAccess) throws IOException, ServletException {
    HttpSession httpSession = request.getSession();
    User user = httpSession != null ? (User) httpSession.getAttribute(SESSION_USER) : null;
    if (user == null) {
        user = findRememberedUser(request);
    }
    // Let's check if we are trying to access a private page and a user has
    // not been defined, in which case, we will forward the request to a login page
    if (privateAccess && user == null) {
        // Redirect to the login page
        String returnUrl = request.getQueryString();
        if (returnUrl.length() > 0) {
            returnUrl = request.getRequestURI() + URLEncoder.encode("?" + returnUrl, "UTF-8");
        } else {
            returnUrl = request.getRequestURI();
        }
        response.sendRedirect("/login?returnUrl=" + returnUrl);
    } else {
        // Start application session
        Session session = Session.start(user, new HttpSessionDelegation(request.getSession()));
        try {
            // Pre-process the request, allowing the application to add certain
            // attributes to the request
            if (preProcessor != null) {
                preProcessor.preProcess(request);
            }
            // Handle the request
            request.getRequestDispatcher(target).forward(request, response);
            session.commit();
        } catch (Exception e) {
            e.printStackTrace();
            LOGGER.error("Error in JSP session", e);
            response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            session.rollback();
        } finally {
            // End the application session
            session.end();
        }
    }
}

[Buggy Hunk]
if (returnUrl.length() > 0) {

[Patch]
if (returnUrl != null && returnUrl.length() > 0) {

[Demonstration 3]

[Buggy Method]
public void KillLiveVN(String path) {
    File file;
    Scanner scanner = null;
    try {
        file = new File(path);
        scanner = new Scanner(file);
        if (!scanner.hasNextLine()) {
            System.out.println("kill Vn read a empty log  file!");
            return;
        }
        String line = scanner.nextLine();
        String[] linearray = line.split(" +");
        while (scanner.hasNextLine()) {
            line = scanner.nextLine();
            linearray = line.split(" +");
            if (linearray[0].equals("VE2PE"))
                break;
            int pnode = Integer.parseInt(linearray[1]);
            double freebandwidth = Double.parseDouble(linearray[2]);
            PGFreeCapacity[pnode] += freebandwidth;
        }
        while (scanner.hasNextLine()) {
            line = scanner.nextLine();
            linearray = line.split(" +");
            double freebandwidth = Double.parseDouble(linearray[linearray.length - 1]);
            for (int i = 0; i < linearray.length - 1; i++) {
                int from = Integer.parseInt(linearray[i]);
                int to = Integer.parseInt(linearray[i + 1]);
                PGFreeBandwidth[from][to] += freebandwidth;
                PGFreeBandwidth[to][from] += freebandwidth;
            }
        }
    } catch (Exception e) {
        System.out.println("int kill live Vn, there is a exception");
        e.printStackTrace();
    } finally {
        scanner.close();
    }
}

[Buggy Hunk]
for(int i = 0; i < linearray.length - 1; i ++){

[Patch]
for(int i = 0; i < linearray.length - 2; i ++){