On Fri, 20 Nov 2020 20:06:38 GMT, Rémi Forax <github.com+828220+fo...@openjdk.org> wrote:
>> I have a fresh look at the different options we have explored (lots of >> challenges in finding the right API with security, usability and performance >> issues to consider). I agree with Remi that we should keep the design and >> API simple and makes it easier to invoke default methods with today's Proxy >> API. We can design a better Proxy API in the future. >> >> The options we have explored are: >> 1. static `InvocationHandler::invokeDefault` method >> 2. abstract `DelegatingInvocationHandler` class with a protected >> `invokeDefault` method >> 3. a new `newProxyInstance` factory method taking a function that produces >> an invocation handler with the ability to invoke a default method via a >> `superHandler` >> >> (1) is very simple API but caller-sensitive. No other API change. Access >> check done at default method invocation time (which is consistent with the >> core reflection `Method::invoke`). It shares the caller class caching in >> `Method::checkAccess` which helps the performance. The performance >> overhead is slightly higher than (2) & (3) which does access check at proxy >> creation time. >> >> (2) is simple and I like that the `invokeDefault` can be enforced to be >> invoked only by the proxy's invocation handler. However this requires more >> API changes (including `newProxyInstance`, `getInvocationHandler`, and new >> unchecked exception type). (3) is clever but a bit over-rotated (how Alan >> describes it) to allow it to be expressed in a lambda expression. If an >> invocation handler wants to save `superHandler`, it can't assign it to a >> final field in lambda and would need to workaround it writing to an array >> element. >> >> I will go with option (1) - static `invokeDefault` method [1] unless there >> is any objection. >> >> CSR: https://bugs.openjdk.java.net/browse/JDK-8253870 >> >> Here is the specdiff: >> http://cr.openjdk.java.net/~mchung/jdk16/webrevs/8159746/specdiff/ >> >> [1] >> http://cr.openjdk.java.net/~mchung/jdk16/webrevs/8159746/api/java.base/java/lang/reflect/InvocationHandler.html#invokeDefault(java.lang.Object,java.lang.reflect.Method,java.lang.Object...) > > Hi Mandy, > thanks for taking the time to explore all the different options, > > The solution 1 is fine for me. Thanks Remi. ------------- PR: https://git.openjdk.java.net/jdk/pull/313