Hi Remi, Jochen,

On 06/02/2016 11:15 AM, fo...@univ-mlv.fr wrote:
>The solution could be for Proxy API to provide a MH that was already
>bound to the Proxy instance. Such pre-bound MH could not be abused then.
independently of any security issue, it may be a good idea but doing a partial 
evaluation on a MH is not cheap.

I created a prototype for this:


Example usage is as follows:

public class Test {

    interface I {
        default void m() {
            System.out.println("default I.m() called");

    public static void main(String[] args) {

        InvocationHandler h = (proxy, method, params) -> {
            System.out.println("InvocationHandler called for: " + method);
MethodHandle superM = ((Proxy) proxy).findSuper(I.class, "m", MethodType.methodType(void.class));
            return superM.invokeWithArguments(params);

        I i = (I) Proxy.newProxyInstance(
            I.class.getClassLoader(), new Class<?>[]{I.class}, h);


It works, but in order for this to have adequate performance, caching would have to be added. But caching a pre-bound MH would require caching on per-proxy-instance basis, which would not be very efficient. So perhaps, instead of providing a Proxy::findSuper method that returns a pre-bound MH, there could simply be a method like the following in the Proxy class:

public final Object invokeSuper(Class<?> interfaze, String methodName, MethodType methodType, Object ... args) { ... }

What do you think?

Regards, Peter

mlvm-dev mailing list

Reply via email to