Re: invoking a interface default method from within an InvocationHandler

2014-12-09 Thread Jochen Theodorou
Am 18.10.2014 18:59, schrieb Peter Levart: [...] The complete solution will require new API, but the java.lang.reflect.Proxy API could be improved a bit too. With introduction of default interface methods it is somehow broken now. I find this a bit strange. A new API means at least JDK9. So JD

Re: invoking a interface default method from within an InvocationHandler

2014-10-22 Thread Remi Forax
On 10/20/2014 11:25 AM, Cédric Champeau wrote: For what it's worth, in Groovy, we have two separate pathes to "implement classes at runtime", that is to say generating proxies. In the case of an interface, we rely on the JDK proxy just because it is *much* faster than generating a class throug

Re: invoking a interface default method from within an InvocationHandler

2014-10-22 Thread Remi Forax
On 10/17/2014 11:58 AM, Paul Sandoz wrote: On Oct 16, 2014, at 12:43 PM, Remi Forax wrote: On 10/15/2014 06:54 PM, Paul Sandoz wrote: Hi Remi, I did some brief evaluation of this area. MethodHandleProxies.asInterfaceInstance currently does not support proxying to default methods. An Inter

Re: invoking a interface default method from within an InvocationHandler

2014-10-22 Thread Cédric Champeau
On 22/10/2014 09:26, Peter Levart wrote: On 10/20/2014 11:25 AM, Cédric Champeau wrote: For what it's worth, in Groovy, we have two separate pathes to "implement classes at runtime", that is to say generating proxies. In the case of an interface, we rely on the JDK proxy just because it is *much

Re: invoking a interface default method from within an InvocationHandler

2014-10-22 Thread Peter Levart
On 10/20/2014 11:25 AM, Cédric Champeau wrote: For what it's worth, in Groovy, we have two separate pathes to "implement classes at runtime", that is to say generating proxies. In the case of an interface, we rely on the JDK proxy just because it is *much* faster than generating a class through A

Re: invoking a interface default method from within an InvocationHandler

2014-10-20 Thread Cédric Champeau
For what it's worth, in Groovy, we have two separate pathes to "implement classes at runtime", that is to say generating proxies. In the case of an interface, we rely on the JDK proxy just because it is *much* faster than generating a class through ASM. I mean that generating a class in ASM is orde

Re: invoking a interface default method from within an InvocationHandler

2014-10-20 Thread Paul Sandoz
On Oct 18, 2014, at 6:59 PM, Peter Levart wrote: > > Hi Paul, Remi, > > The complete solution will require new API, but the java.lang.reflect.Proxy > API could be improved a bit too. With introduction of default interface > methods it is somehow broken now. Default interface methods enable in

Re: invoking a interface default method from within an InvocationHandler

2014-10-18 Thread Peter Levart
On 10/17/2014 11:58 AM, Paul Sandoz wrote: On Oct 16, 2014, at 12:43 PM, Remi Forax wrote: On 10/15/2014 06:54 PM, Paul Sandoz wrote: Hi Remi, I did some brief evaluation of this area. MethodHandleProxies.asInterfaceInstance currently does not support proxying to default methods. An Inter

Re: invoking a interface default method from within an InvocationHandler

2014-10-17 Thread Paul Sandoz
On Oct 16, 2014, at 12:43 PM, Remi Forax wrote: > > On 10/15/2014 06:54 PM, Paul Sandoz wrote: >> Hi Remi, >> >> I did some brief evaluation of this area. >> >> MethodHandleProxies.asInterfaceInstance currently does not support proxying >> to default methods. An InternalError will be thrown

Re: invoking a interface default method from within an InvocationHandler

2014-10-16 Thread Remi Forax
On 10/15/2014 06:54 PM, Paul Sandoz wrote: Hi Remi, I did some brief evaluation of this area. MethodHandleProxies.asInterfaceInstance currently does not support proxying to default methods. An InternalError will be thrown if a default method is invoked. It should be possible to fix using a t

Re: invoking a interface default method from within an InvocationHandler

2014-10-15 Thread Paul Sandoz
Hi Remi, I did some brief evaluation of this area. MethodHandleProxies.asInterfaceInstance currently does not support proxying to default methods. An InternalError will be thrown if a default method is invoked. It should be possible to fix using a trusted internal IMPL_LOOKUP to look up MHs th

Re: invoking a interface default method from within an InvocationHandler

2014-10-09 Thread Remi Forax
Thinking a little bit more about that, you can almost use a lambda proxy as a reflect proxy, yes, almost because the lambda metafactory doesn't understand varargs. class Main { public static void print(Object... args) { System.out.println(Arrays.toString(args)); } public static void m

Re: invoking a interface default method from within an InvocationHandler

2014-10-09 Thread Jochen Theodorou
Am 09.10.2014 19:07, schrieb Remi Forax: public static void main(String[] args) throws NoSuchFieldException, IllegalArgumentException, IllegalAccessException { Lookup lookup = MethodHandles.publicLookup().in(Consumer.class); Field allowedModes = Lookup.class.getDeclaredField("allowedMod

Re: invoking a interface default method from within an InvocationHandler

2014-10-09 Thread Jochen Theodorou
Am 09.10.2014 17:32, schrieb Alessio Stalla: [...] Well, you can extend this technique by using more method references and delegation (yes, even more levels of indirection!), in short: I should just produce my own proxy system ;) Or in other words, there is no proper replacement in the JDK for

Re: invoking a interface default method from within an InvocationHandler

2014-10-09 Thread Remi Forax
public static void main(String[] args) throws NoSuchFieldException, IllegalArgumentException, IllegalAccessException { Lookup lookup = MethodHandles.publicLookup().in(Consumer.class); Field allowedModes = Lookup.class.getDeclaredField("allowedModes"); allowedModes.setAccessible(true);

Re: invoking a interface default method from within an InvocationHandler

2014-10-09 Thread Alessio Stalla
On Thu, Oct 9, 2014 at 5:22 PM, Jochen Theodorou wrote: > Am 09.10.2014 17:02, schrieb Alessio Stalla: > >> "All problems in computer science can be solved by another level of >> indirection"... "except for the problem of too many layers of >> indirection". >> >> What about (untested): >> >> Cons

Re: invoking a interface default method from within an InvocationHandler

2014-10-09 Thread Jochen Theodorou
Am 09.10.2014 17:02, schrieb Alessio Stalla: "All problems in computer science can be solved by another level of indirection"... "except for the problem of too many layers of indirection". What about (untested): Consumer proxy = Proxy.newProxyInstance(...); Consumer myConsumer = proxy::accept;

Re: invoking a interface default method from within an InvocationHandler

2014-10-09 Thread Jochen Theodorou
Am 09.10.2014 16:51, schrieb Vladimir Ivanov: Jochen, too bad no-one knows. Has anyone an idea for a better place to ask this? (btw, because of the getSimpleName issue I can't use MethodHandleProxies) FYI, I plan to get MethodType.toString() problem fixed in 8u40. I wish you would know how o

Re: invoking a interface default method from within an InvocationHandler

2014-10-09 Thread Alessio Stalla
"All problems in computer science can be solved by another level of indirection"... "except for the problem of too many layers of indirection". What about (untested): Consumer proxy = Proxy.newProxyInstance(...); Consumer myConsumer = proxy::accept; If you keep the proxy inaccessible, nobody wil

Re: invoking a interface default method from within an InvocationHandler

2014-10-09 Thread Vladimir Ivanov
Jochen, too bad no-one knows. Has anyone an idea for a better place to ask this? (btw, because of the getSimpleName issue I can't use MethodHandleProxies) FYI, I plan to get MethodType.toString() problem fixed in 8u40. Best regards, Vladimir Ivanov Am 06.10.2014 18:06, schrieb Jochen Theodo

Re: invoking a interface default method from within an InvocationHandler

2014-10-09 Thread Jochen Theodorou
too bad no-one knows. Has anyone an idea for a better place to ask this? (btw, because of the getSimpleName issue I can't use MethodHandleProxies) Am 06.10.2014 18:06, schrieb Jochen Theodorou: Hi, I find this a little odd and I wonder how you are supposed to do it right. Or if that is a bug

invoking a interface default method from within an InvocationHandler

2014-10-06 Thread Jochen Theodorou
Hi, I find this a little odd and I wonder how you are supposed to do it right. Or if that is a bug. So I have a class implementing InvocationHandler and I used Proxy to create a an proxied instance of Consumer. This is a functional interface and I want to use its accept method for my purpose