[Demonstration 1]

[Buggy Method]
@Override
@SuppressWarnings("unchecked")
public final ResponseHandler apply(final MocoConfig config) {
    if (config.isFor(MocoConfig.RESPONSE_ID)) {
        return (ResponseHandler) config.apply(this);
    }
    return this;
}

[Buggy Hunk]
public final ResponseHandler apply(final MocoConfig config) {

[Patch]
public ResponseHandler apply(final MocoConfig config) {

[Demonstration 2]

[Buggy Method]
private void parseMethod(Invokable<?, ?> method) {
    Request request = method.getAnnotation(Request.class);
    this.urlTemplate = UrlTemplate.create(request.url());
    this.asynchronous = isAsynchronous(method);
    this.method = request.method();
    /* If instance wrapped with Observable, we should extract generic type parameter */
    this.responseType = asynchronous ? getGenericSubtype(method.getReturnType()) : method.getReturnType().getType();
    this.returnBodyOnly = bodyOnly(method);
    /* walk through method parameters and find marked with internal annotations */
    ImmutableList<Parameter> methodParameters = method.getParameters();
    for (int i = 0; i < methodParameters.size(); i++) {
        Parameter parameter = methodParameters.get(i);
        if (parameter.isAnnotationPresent(Path.class)) {
            Path path = parameter.getAnnotation(Path.class);
            assert path != null;
            Preconditions.checkState(urlTemplate.hasPathVariable(path.value()), "There is no path parameter with name '%s' declared in url template", path.value());
            pathArguments.put(i, path.value());
        } else if (parameter.isAnnotationPresent(Body.class)) {
            this.bodyArgument = Optional.of(i);
            if (parameter.isAnnotationPresent(Multipart.class)) {
                Preconditions.checkArgument(TypeToken.of(MultiPartRequest.class).isSupertypeOf(parameter.getType()), "@Multipart parameters are expected to be MultiPartRequest. '%s' is not a MultiPartRequest", parameter.getType());
                multiPart = true;
            }
        } else if (parameter.isAnnotationPresent(Query.class)) {
            Preconditions.checkArgument(TypeToken.of(Map.class).isSupertypeOf(parameter.getType()), "@Query parameters are expected to be maps. '%s' is not a Map", parameter.getType());
            this.queryParameter = Optional.of(i);
        }
    }
    validationPathArguments(method);
}

[Buggy Hunk]
this.responseType = asynchronous ? getGenericSubtype(method.getReturnType()) : method.getReturnType().getType();

[Patch]
this.responseType = getResponseType(method);

[Demonstration 3]

[Buggy Method]
private <Res> void handle400HttpError(HttpStatusCodeException errorResponse, Class<Res> responseType) {
    ConnectResponse response = (new Gson()).fromJson(errorResponse.getResponseBodyAsString(), responseType);
    LOGGER.error("Handling 400 Bad request :" + errorResponse.getResponseBodyAsString());
    LOGGER.debug("Error response : " + response);
    throw new ApplicationValidationException(response.getErrorMessage());
}

[Buggy Hunk]
ConnectResponse response = (new Gson()).fromJson(

[Patch]
ConnectResponse response = (ConnectResponse) (new Gson()).fromJson(