[Demonstration 1]

[Buggy Method]
public Organism[][] loadPattern(File f) throws FileNotFoundException {
    assert f.isFile() : f;
    // Read all the lines from the file
    Scanner s = new Scanner(f);
    List<String> lines = new ArrayList<String>();
    while (s.hasNextLine()) {
        lines.add(s.nextLine());
    }
    // Convert the list of lines to an array
    String[][] table = new String[lines.size()][5];
    for (int i = 0; i < table.length; i++) {
        // The file can be space-, comma-, or tab-separated
        table[i] = lines.get(i).split("[\t, ]");
    }
    // Find the largest row and column in the table to determine
    // the new organism array size
    int maxR = 0;
    int maxC = 0;
    for (int i = 0; i < table.length; i++) {
        maxR = Math.max(Integer.parseInt(table[i][0]), maxR);
        maxC = Math.max(Integer.parseInt(table[i][1]), maxC);
    }
    // Create and fill the new organism array
    Organism[][] board = new Organism[maxR][maxC];
    for (int i = 0; i < table.length; i++) {
        try {
            int r = Integer.parseInt(table[i][0]);
            int c = Integer.parseInt(table[i][1]);
            int age = Integer.parseInt(table[i][3]);
            int foodLevel = Integer.parseInt(table[i][4]);
            if (table[i][2].equals("f")) {
                board[r][c] = new Fish(age, foodLevel);
            } else if (table[i][2].equals("s")) {
                board[r][c] = new Shark(age, foodLevel);
            } else if (table[i][3].equals("a")) {
                //Algae good level is always 0
                board[r][c] = new Algae(age, 0);
            }
        } catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
            // If a row is invalid, ignore it and move to the next one
            continue;
        }
    }
    return board;
}

[Buggy Hunk]
public Organism[][] loadPattern(File f) throws FileNotFoundException {

[Patch]
public static Organism[][] loadPattern(File f) throws FileNotFoundException {

[Demonstration 2]

[Buggy Method]
public static void main(String[] args) throws Exception {
    if (args.length != 3) {
        usage();
        return;
    }
    Protein p = new Protein(args[0]);
    Scanner sc = new Scanner(new File(args[1]));
    FileWriter os = new FileWriter(new File(args[2]));
    sc.nextLine();
    os.write("Point,X,Y,Z,R");
    String line;
    Atom3D temp;
    double x, y, z;
    String[] split;
    while (sc.hasNextLine()) {
        line = sc.nextLine();
        split = line.split(",");
        x = Double.parseDouble(split[1]);
        y = Double.parseDouble(split[2]);
        z = Double.parseDouble(split[3]);
        temp = p.curvature(x, y, z);
        os.write("\n" + split[0] + "," + temp.x + "," + temp.y + "," + temp.z + "," + temp.z);
    }
    sc.close();
    os.close();
}

[Buggy Hunk]
+ temp.z + "," + temp.z);

[Patch]
+ temp.z + "," + temp.r);

[Demonstration 3]

[Buggy Method]
private JSONObject toJsonObject(Resource resource) {
    List<Field> fields = getFields(new ArrayList<Field>(), resource.getClass());
    JSONObject mainNode = new JSONObject();
    try {
        JSONObject content = new JSONObject();
        JSONObject attributes = new JSONObject();
        JSONObject relationship = new JSONObject();
        JSONArray include = new JSONArray();
        //Processar os dados
        content.put("type", resource.getClass().getAnnotation(Type.class).value());
        for (Field field : fields) {
            String fieldName = null;
            Boolean oldAccessible = field.isAccessible();
            field.setAccessible(true);
            if (field.getAnnotation(Excluded.class) != null)
                continue;
            if (field.getAnnotation(SerialName.class) != null) {
                fieldName = field.getAnnotation(SerialName.class).value();
            }
            if (fieldName == null)
                fieldName = field.getName();
            if (Collection.class.isAssignableFrom(field.getType())) {
                JSONArray array = new JSONArray();
                List<?> list = (List) field.get(resource);
                if (list.size() > 0) {
                    for (Object listItem : list) {
                        if (listItem instanceof String) {
                            array.put(String.valueOf(listItem));
                        } else if (listItem instanceof Integer) {
                            array.put((int) listItem);
                        } else if (listItem instanceof Double || listItem instanceof Float) {
                            array.put(Double.valueOf(String.valueOf(listItem)));
                        } else if (listItem instanceof Long) {
                            array.put((Long) listItem);
                        } else if (listItem instanceof Character) {
                            array.put(Character.toString((char) listItem));
                        } else if (listItem instanceof Boolean) {
                            array.put((boolean) listItem);
                        } else if (listItem instanceof Date) {
                            array.put(dateFormatToServer.format((Date) field.get(resource)).replace(" ", "T"));
                        } else if (listItem instanceof Resource) {
                            JSONObject relationshipNode = null;
                            JSONArray relationshipNodeData = null;
                            if (relationship.isNull(fieldName)) {
                                relationshipNode = new JSONObject();
                            } else {
                                relationshipNode = relationship.getJSONObject(fieldName);
                            }
                            if (relationshipNode.isNull("data")) {
                                relationshipNodeData = new JSONArray();
                            } else {
                                relationshipNodeData = relationshipNode.getJSONArray("data");
                            }
                            relationshipNodeData.put(getNodeAsRelationship(listItem));
                            relationshipNode.put("data", relationshipNodeData);
                            relationship.put(fieldName, relationshipNode);
                            include.put(getNodeAsInclude(listItem));
                        }
                    }
                }
                if (array.length() > 0)
                    attributes.put(fieldName, array);
            } else {
                if (field.getAnnotation(Id.class) != null) {
                    content.put("id", String.valueOf(field.get(resource)));
                } else if (field.get(resource) instanceof String) {
                    attributes.put(fieldName, String.valueOf(field.get(resource)));
                } else if (field.get(resource) instanceof Integer) {
                    attributes.put(fieldName, field.getInt(resource));
                } else if (field.get(resource) instanceof Double || field.get(resource) instanceof Float) {
                    attributes.put(fieldName, Double.valueOf(String.valueOf(field.get(resource))));
                } else if (field.get(resource) instanceof Long) {
                    attributes.put(fieldName, field.getLong(resource));
                } else if (field.get(resource) instanceof Character) {
                    attributes.put(fieldName, Character.toString(field.getChar(resource)));
                } else if (field.get(resource) instanceof Boolean) {
                    attributes.put(fieldName, field.getBoolean(resource));
                } else if (field.get(resource) instanceof Date) {
                    attributes.put(fieldName, dateFormatToServer.format((Date) field.get(resource)).replace(" ", "T"));
                } else if (field.get(resource) instanceof Resource) {
                    JSONObject relationshipNode = new JSONObject();
                    relationshipNode.put("data", getNodeAsRelationship(field.get(resource)));
                    relationship.put(fieldName, relationshipNode);
                    include.put(getNodeAsInclude(field.get(resource)));
                }
            }
            field.setAccessible(oldAccessible);
        }
        content.put("attributes", attributes);
        if (relationship.length() > 0)
            content.put("relationships", relationship);
        mainNode.put("data", content);
        if (include.length() > 0)
            mainNode.put("included", include);
    } catch (Exception ex) {
        //Tratar erros
        ex.printStackTrace();
    }
    return mainNode;
}

[Buggy Hunk]
content.put("type", resource.getClass().getAnnotation(Type.class).value());

[Patch]
content.put("type", resource.getType());