[Demonstration 1]

[Buggy Method]
@Override
protected DCAResponse execute() throws Exception {
    DCAResponse response = new DCAResponse(ErrorCodeConstant.SUCCESSUL.getErrorCode());
    List<String> result = new ArrayList<String>();
    String[] keywords;
    switch(type) {
        case INGREDIENT_TYPE:
            keywords = keyword.split(",+");
            keyword = keywords[keywords.length - 1];
            List<Ingredient> list = IngredientDAO.getInstance().list(keyword, 0, 3);
            if (list != null)
                for (Ingredient in : list) result.add(in.getName());
            break;
        case TAG_TYPE:
            keywords = keyword.split(",+");
            keyword = keywords[keywords.length - 1];
            List<Tag> tags = TagDAO.getInstance().list(keyword, 0, 3);
            if (tags != null)
                for (Tag tag : tags) result.add(tag.getTag());
            break;
        case NAME_TYPE:
            List<Recipe> recipes = RecipeDAO.getInstance().getRecipeForSuggestion(keyword, 0, 3);
            if (recipes != null)
                for (Recipe recipe : recipes) result.add(recipe.getTitle());
            break;
    }
    response.setData(result);
    return response;
}

[Buggy Hunk]
List<Tag> tags = TagDAO.getInstance().list(keyword, 0, 3);

[Patch]
List<Tag> tags = TagDAO.getInstance().list(keyword.trim(), 0, 3);

[Demonstration 2]

[Buggy Method]
public Command parse(String args) throws IllegalValueException {
    final Matcher matcher = KEYWORDS_ARGS_FORMAT.matcher(args.trim());
    if (!matcher.matches()) {
        return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindCommand.MESSAGE_USAGE));
    }
    // keywords delimited by whitespace
    final String[] keywords = matcher.group("keywords").split("\\s+");
    if (keywords[0].charAt(0) == PREFIX_HASHTAG) {
        return returnFindCommandForHashtagPrefix(keywords);
    }
    final Set<String> keywordSet = new HashSet<>(Arrays.asList(keywords));
    return new FindCommand(keywordSet);
}

[Buggy Hunk]
return returnFindCommandForHashtagPrefix(keywords);

[Patch]
return returnFindCommandForHashtagPrefix(keywords[0]);

[Demonstration 3]

[Buggy Method]
@Override
public void handle(HttpExchange httpExchange) throws IOException {
    try {
        String path = httpExchange.getRequestURI().getPath();
        if (!path.startsWith(apiPrefix))
            throw new IllegalStateException("Unsupported api version, required: " + apiPrefix);
        path = path.substring(apiPrefix.length());
        // N.B. URI.getQuery() decodes the query string
        Map<String, List<String>> params = parseQuery(httpExchange.getRequestURI().getQuery());
        List<String> args = params.get("arg");
        Function<String, String> last = key -> params.get(key).get(params.get(key).size() - 1);
        switch(path) {
            case "block/put":
                {
                    PublicSigningKey writer = PublicSigningKey.fromString(last.apply("writer"));
                    String boundary = httpExchange.getRequestHeaders().get("Content-Type").stream().filter(s -> s.contains("boundary=")).map(s -> s.substring(s.indexOf("=") + 1)).findAny().get();
                    List<byte[]> data = MultipartReceiver.extractFiles(httpExchange.getRequestBody(), boundary);
                    dht.put(writer, data).thenAccept(hashes -> {
                        List<Object> json = hashes.stream().map(h -> wrapHash(h)).collect(Collectors.toList());
                        // make stream of JSON objects
                        String jsonStream = json.stream().map(m -> JSONParser.toString(m)).reduce("", (a, b) -> a + b);
                        replyJson(httpExchange, jsonStream, Optional.empty());
                    }).exceptionally(Futures::logError);
                    break;
                }
            case "block/get":
                {
                    Multihash hash = Cid.decode(args.get(0));
                    dht.get(hash).thenAccept(opt -> replyBytes(httpExchange, opt.map(cbor -> cbor.toByteArray()).orElse(new byte[0]), Optional.of(hash))).exceptionally(Futures::logError);
                    break;
                }
            case "pin/add":
                {
                    Multihash hash = Cid.decode(args.get(0));
                    dht.recursivePin(hash).thenAccept(pinned -> {
                        Map<String, Object> json = new TreeMap<>();
                        json.put("Pins", pinned.stream().map(h -> h.toString()).collect(Collectors.toList()));
                        replyJson(httpExchange, JSONParser.toString(json), Optional.empty());
                    }).exceptionally(Futures::logError);
                    break;
                }
            case "pin/rm":
                {
                    boolean recursive = params.containsKey("r") && Boolean.parseBoolean(last.apply("r"));
                    if (!recursive)
                        throw new IllegalStateException("Unimplemented: non recursive unpin!");
                    Multihash hash = Cid.decode(args.get(0));
                    dht.recursiveUnpin(hash).thenAccept(unpinned -> {
                        Map<String, Object> json = new TreeMap<>();
                        json.put("Pins", unpinned.stream().map(h -> h.toString()).collect(Collectors.toList()));
                        replyJson(httpExchange, JSONParser.toString(json), Optional.empty());
                    }).exceptionally(Futures::logError);
                    break;
                }
            default:
                {
                    httpExchange.sendResponseHeaders(404, 0);
                }
        }
    } catch (Exception e) {
        System.err.println("Error handling " + httpExchange.getRequestURI());
        e.printStackTrace();
        replyError(httpExchange, e);
    }
}

[Buggy Hunk]
opt.map(cbor -> cbor.toByteArray()).orElse(new byte[0]), Optional.of(hash)))

[Patch]
opt.map(CborObject::toByteArray).orElse(new byte[0]), opt.map(x -> hash)))