[Demonstration 1]

[Buggy Method]
public static void sendIiifInfo(DigilibServletRequest dlReq, HttpServletResponse response, Logger logger) throws ServletException {
    if (response == null) {
        logger.error("No response!");
        return;
    }
    /*
         * get image size
         */
    ImageSize size = null;
    ImageSet imageSet = null;
    try {
        // get original image size
        imageSet = dlReq.getJobDescription().getImageSet();
        ImageInput img = imageSet.getBiggest();
        size = img.getSize();
    } catch (FileOpException e) {
        try {
            response.sendError(HttpServletResponse.SC_NOT_FOUND);
            return;
        } catch (IOException e1) {
            throw new ServletException("Unable to write error response!", e);
        }
    }
    /*
         * get resource URL
         */
    String url = dlReq.getServletRequest().getRequestURL().toString();
    if (url.endsWith("/info.json")) {
        url = url.substring(0, url.lastIndexOf("/info.json"));
    } else if (url.endsWith("/")) {
        url = url.substring(0, url.lastIndexOf("/"));
    }
    /*
         * send response
         */
    response.setCharacterEncoding("UTF-8");
    logger.debug("sending info.json");
    try {
        /*
             * set CORS header ACAO "*" for info response as per IIIF spec
             */
        if (dlReq.getDigilibConfig().getAsBoolean("iiif-info-cors")) {
            String origin = dlReq.getServletRequest().getHeader("Origin");
            if (origin != null) {
                response.setHeader("Access-Control-Allow-Origin", "*");
            }
        }
        PrintWriter writer;
        if (dlReq.getDigilibConfig().getAsString("iiif-api-version").startsWith("2.")) {
            /*
                 * IIIF Image API version 2 image information
                 */
            // use JSON-LD content type only when asked
            String accept = dlReq.getServletRequest().getHeader("Accept");
            if (accept != null && accept.contains("application/ld+json")) {
                response.setContentType("application/ld+json");
            } else {
                response.setContentType("application/json");
                response.setHeader("Link", "<http://iiif.io/api/image/2/context.json>" + "; rel=\"http://www.w3.org/ns/json-ld#context\"" + "; type=\"application/ld+json\"");
            }
            // write info.json
            writer = response.getWriter();
            writer.println("{");
            writer.println("\"@context\" : \"http://iiif.io/api/image/2/context.json\",");
            writer.println("\"@id\" : \"" + url + "\",");
            writer.println("\"@protocol\" : \"http://iiif.io/api/image\",");
            writer.println("\"width\" : " + size.width + ",");
            writer.println("\"height\" : " + size.height + ",");
            writer.println("\"profile\" : [");
            writer.println("  \"http://iiif.io/api/image/2/level2.json\",");
            writer.println("  {");
            writer.println("    \"formats\" : [\"jpg\", \"png\"],");
            writer.println("    \"qualities\" : [\"color\", \"gray\"],");
            writer.println("    \"supports\" : [\"mirroring\", \"rotationArbitrary\", \"sizeAboveFull\"]");
            writer.println("  }]");
            // add sizes of prescaled images
            int numImgs = imageSet.size();
            if (numImgs > 1) {
                writer.println(", \"sizes\" : [");
                for (int i = numImgs - 1; i > 0; --i) {
                    ImageInput ii = imageSet.get(i);
                    ImageSize is = ii.getSize();
                    writer.println("  {\"width\" : " + is.getWidth() + ", \"height\" : " + is.getHeight() + "}" + ((i > 1) ? "," : ""));
                }
                writer.println("]");
            }
            writer.println("}");
        } else {
            /*
                 * IIIF Image API version 1 image information
                 */
            response.setContentType("application/json,application/ld+json");
            writer = response.getWriter();
            writer.println("{");
            writer.println("\"@context\" : \"http://library.stanford.edu/iiif/image-api/1.1/context.json\",");
            writer.println("\"@id\" : \"" + url + "\",");
            writer.println("\"width\" : " + size.width + ",");
            writer.println("\"height\" : " + size.height + ",");
            writer.println("\"formats\" : [\"jpg\", \"png\"],");
            writer.println("\"qualities\" : [\"native\", \"color\", \"grey\"],");
            writer.println("\"profile\" : \"http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level2\"");
            writer.println("}");
        }
    } catch (IOException e) {
        throw new ServletException("Unable to write response!", e);
    }
}

[Buggy Hunk]
writer.println("\"@protocol\" : \"http://iiif.io/api/image\",");

[Patch]
writer.println("\"protocol\" : \"http://iiif.io/api/image\",");

[Demonstration 2]

[Buggy Method]
public int getPending() {
    if (agentOptions.getEnabled()) {
        return 0;
    } else {
        return connection.messages.size();
    }
}

[Buggy Hunk]
if (agentOptions.getEnabled()) {

[Patch]
if (!agentOptions.getEnabled()) {

[Demonstration 3]

[Buggy Method]
public int getNeigbours(int i, int r) {
    int am = 0;
    int le = cellArrayStatus.length;
    if (i - 1 >= 0 && r - 1 >= 0) {
        if (cellArrayStatus[i - 1][r - 1]) {
            am++;
        }
    }
    if (i - 1 >= 0) {
        if (cellArrayStatus[i - 1][r]) {
            am++;
        }
    }
    if (i - 1 >= 0 && r + 1 < le) {
        if (cellArrayStatus[i - 1][r + 1]) {
            am++;
        }
    }
    if (r + 1 < le) {
        if (cellArrayStatus[i][r + 1]) {
            am++;
        }
    }
    if (i + 1 < le && r + 1 < le) {
        if (cellArrayStatus[i + 1][r + 1]) {
            am++;
        }
    }
    if (i + 1 < le) {
        if (cellArrayStatus[i + 1][r]) {
            am++;
        }
    }
    if (i + 1 < le && r - 1 >= 0) {
        if (cellArrayStatus[i + 1][r - 1]) {
            am++;
        }
    }
    if (r - 1 >= 0) {
        if (cellArrayStatus[i][r - 1]) {
            am++;
        }
    }
    return am;
}

[Buggy Hunk]
public int getNeigbours(int i, int r){

[Patch]
private int getNeigbours(int i, int r){