[Demonstration 1]

[Buggy Method]
private Inflector<ContainerRequestContext, Response> utilsHandler() {
    return new Inflector<ContainerRequestContext, Response>() {

        public Response apply(ContainerRequestContext ctx) {
            MultivaluedMap<String, String> params = ctx.getUriInfo().getQueryParameters();
            String method = pathParam("method", ctx);
            method = StringUtils.isBlank(method) ? params.getFirst("method") : method;
            if ("newid".equals(method)) {
                return Response.ok(Utils.getNewId()).build();
            } else if ("timestamp".equals(method)) {
                return Response.ok(Utils.timestamp()).build();
            } else if ("formatdate".equals(method)) {
                String format = params.getFirst("format");
                String locale = params.getFirst("locale");
                Locale loc = LocaleUtils.toLocale(locale);
                return Response.ok(Utils.formatDate(format, loc)).build();
            } else if ("formatmessage".equals(method)) {
                String msg = params.getFirst("message");
                Object[] paramz = params.get("fields").toArray();
                return Response.ok(Utils.formatMessage(msg, paramz)).build();
            } else if ("nospaces".equals(method)) {
                String str = params.getFirst("string");
                String repl = params.getFirst("replacement");
                return Response.ok(Utils.noSpaces(str, repl)).build();
            } else if ("nosymbols".equals(method)) {
                String str = params.getFirst("string");
                return Response.ok(Utils.stripAndTrim(str)).build();
            } else if ("md2html".equals(method)) {
                String md = params.getFirst("md");
                return Response.ok(Utils.markdownToHtml(md), MediaType.TEXT_HTML).build();
            } else if ("timeago".equals(method)) {
                String d = params.getFirst("delta");
                long delta = NumberUtils.toLong(d, 1);
                return Response.ok(HumanTime.approximately(delta)).build();
            }
            return RestUtils.getStatusResponse(Response.Status.BAD_REQUEST, "Unknown method: " + ((method == null) ? "empty" : method));
        }
    };
}

[Buggy Hunk]
Locale loc = LocaleUtils.toLocale(locale);

[Patch]
Locale loc = getLocale(locale);

[Demonstration 2]

[Buggy Method]
public void send() {
    if (handler.handle())
        return;
    for (int i = 0; i < children.size(); i++) {
        String id = children.getValue(i).toString();
        Object object = app.getScriptEngine().get(id);
        if (object != null && object instanceof Control) {
            Control control = (Control) object;
            if (control.getName() == null || control.getName().isEmpty())
                continue;
            jsonObject.put(control.getName(), control.getValue());
        }
    }
    app.send(jsonObject, method, action);
}

[Buggy Hunk]
Object object = app.getScriptEngine().get(id);

[Patch]
Object object = app.getContext().get(id);

[Demonstration 3]

[Buggy Method]
public static final String getSessionId() throws MovieDbException {
    LOG.info("Create a session token for the rest of the tests");
    if (tokenSession == null) {
        String filename = TokenSession.class.getSimpleName();
        // Try to read the object from a file
        tokenSession = readObject(filename);
        if (tokenSession == null) {
            TmdbAuthentication auth = new TmdbAuthentication(getApiKey(), getHttpTools());
            // 1: Create a request token
            TokenAuthorisation token = auth.getAuthorisationToken();
            assertTrue("Token (auth) is not valid", token.getSuccess());
            token = auth.getSessionTokenLogin(token, getUsername(), getPassword());
            assertTrue("Token (login) is not valid", token.getSuccess());
            // 3: Create the sessions ID
            tokenSession = auth.getSessionToken(token);
            assertTrue("Session token is not valid", tokenSession.getSuccess());
            // Write the object to a file
            writeObject(token, filename);
        }
    }
    return tokenSession.getSessionId();
}

[Buggy Hunk]
writeObject(token, filename);

[Patch]
writeObject(tokenSession, filename);