[Demonstration 1]

[Buggy Method]
private static Method findMethod(Class<?> clazz, String methodName, Class[] types) {
    if (clazz == null)
        throw new IllegalArgumentException("Null class");
    if (methodName == null)
        throw new IllegalArgumentException("Null method name");
    try {
        Class<?> current = clazz;
        while (current != null) {
            try {
                final Method m = clazz.getDeclaredMethod(methodName, types);
                m.setAccessible(true);
                return m;
            } catch (NoSuchMethodException ignored) {
            }
            current = current.getSuperclass();
        }
    } catch (Throwable t) {
        throw new RuntimeException(t);
    }
    throw new IllegalStateException("Couldn't invoke method: " + clazz.getName() + " / " + methodName);
}

[Buggy Hunk]
final Method m = clazz.getDeclaredMethod(methodName, types);

[Patch]
final Method m = current.getDeclaredMethod(methodName, types);

[Demonstration 2]

[Buggy Method]
@SuppressWarnings({ "rawtypes", "unchecked" })
private Object execute(final Method method, final Object... args) throws RpcException {
    try {
        final RpcClient.Builder<RpcRequest, RpcResponse> clientBuilder = getRpcClient(method, args).newBuilder();
        // Set RPC timeout
        final Timeout timeout = method.isAnnotationPresent(Timeout.class) ? method.getAnnotation(Timeout.class) : this.service.getAnnotation(Timeout.class);
        if (null != timeout) {
            clientBuilder.setConnectTimeout(timeout.connectTimeout());
            clientBuilder.setReadTimeout(timeout.readTimeout());
            clientBuilder.setWriteTimeout(timeout.writeTimeout());
        }
        // Set RPC DNS resolver
        final DnsResolution dns = method.isAnnotationPresent(DnsResolution.class) ? method.getAnnotation(DnsResolution.class) : this.service.getAnnotation(DnsResolution.class);
        if (null != dns) {
            clientBuilder.setDnsResolver(dns.value().newInstance());
        }
        // Set RPC interceptors
        final Interception interception = method.isAnnotationPresent(Interception.class) ? method.getAnnotation(Interception.class) : this.service.getAnnotation(Interception.class);
        if (null != interception) {
            for (final Class<? extends RpcInterceptor> clazz : interception.value()) {
                if (null != clazz) {
                    clientBuilder.addInterceptor(clazz.newInstance());
                }
            }
        }
        final RpcClient<RpcRequest, RpcResponse> client = clientBuilder.build();
        final RpcRequest request = client.newRequestBuilder().setUrl(this.baseUrl).setService(this.service, method, args).build();
        final Rpc<RpcRequest, RpcResponse> rpc = client.newRpc(request);
        final Object result;
        if (args.length > 0 && args[args.length - 1] instanceof RpcService.Callback) {
            final RpcService.Callback callback = (RpcService.Callback) args[args.length - 1];
            result = rpc.enqueue(new Rpc.Callback<RpcRequest, RpcResponse>() {

                @Override
                public void onSuccess(final RpcResponse response) {
                    try {
                        callback.onSuccess(response.getContent());
                    } catch (final IOException e) {
                        callback.onFailure(new RpcException(e));
                    }
                }

                @Override
                public void onFailure(final RpcRequest request, final RpcException e) {
                    callback.onFailure(e);
                }
            });
        } else {
            result = rpc.execute().getContent();
        }
        final Class<?> retType = method.getReturnType();
        if (void.class.equals(retType) || Void.class.equals(retType)) {
            return null;
        }
        return result;
    } catch (final RpcException e) {
        throw e;
    } catch (final Throwable e) {
        throw new RpcException(e);
    }
}

[Buggy Hunk]
.setService(this.service, method, args)

[Patch]
.setRpcService(this.service, method, args)

[Demonstration 3]

[Buggy Method]
public static Result service(String ownerName, String projectName, String service, boolean isAdvertise) throws IOException, UnsupportedOperationException, ServletException {
    if (!isSupportedService(service)) {
        return forbidden(String.format("Unsupported service: '%s'", service));
    }
    Project project = Project.findByOwnerAndProjectName(ownerName, projectName);
    if (project == null) {
        return notFound();
    }
    models.User user = UserApp.currentUser();
    if (!isAllowed(project, service)) {
        if (user.isAnonymous()) {
            return BasicAuthAction.unauthorized(response());
        } else {
            // If you want the Git client showing your custom message to
            // the user, the Content-Type should be exact "text/plain"
            // without any parameter. For more details, see the code at
            // https://github.com/git/git/commit/426e70d4a11ce3b4f70636d57c6a0ab16ae08a00#diff-eea0ad565ec5903a11b6023755d491cfR154
            response().setHeader("Content-Type", "text/plain");
            return forbidden(String.format("'%s' has no permission to '%s/%s'.", user.name, ownerName, projectName));
        }
    }
    if (isAdvertise) {
        return ok(RepositoryService.gitAdvertise(project, service, response()));
    } else {
        if (request().body().isMaxSizeExceeded()) {
            return status(REQUEST_ENTITY_TOO_LARGE);
        } else {
            user.visits(project);
            return ok(RepositoryService.gitRpc(project, service, request(), response()));
        }
    }
}

[Buggy Hunk]
user.name, ownerName, projectName));

[Patch]
user.loginId, ownerName, projectName));