On 27.05.2016 08:58, fo...@univ-mlv.fr wrote:
----- Mail original -----
De: "Jochen Theodorou" <blackd...@gmx.org>
À: "Remi Forax" <fo...@univ-mlv.fr>
Cc: "jigsaw-dev" <jigsaw-dev@openjdk.java.net>
Envoyé: Vendredi 27 Mai 2016 07:28:58
Objet: Re: creating proxies for interfaces with default methods
On 26.05.2016 14:00, Remi Forax wrote:
Not if you use Lookup.findSpecial() [1]
Anyway, you can not use it because you can not get the Lookup object
associated with the proxy class.
which is why I did this:
MethodHandles.Lookup.class.getDeclaredConstructor(Class.class,
int.class).
newInstance(interfaceClass, MethodHandles.Lookup.PRIVATE).
unreflectSpecial(method, interfaceClass).
bindTo(receiver);
but that is not working anymore.
??, what's the exact error ?
java.lang.AssertionError: java.util.Comparator/2
at
java.lang.invoke.MethodHandles$Lookup.toString(java.base@9-ea/MethodHandles.java:792)
at java.lang.String.valueOf(java.base@9-ea/String.java:2806)
at java.lang.StringBuilder.append(java.base@9-ea/StringBuilder.java:135)
at
java.lang.invoke.MemberName.makeAccessException(java.base@9-ea/MemberName.java:867)
at
java.lang.invoke.MethodHandles$Lookup.checkAccess(java.base@9-ea/MethodHandles.java:1642)
at
java.lang.invoke.MethodHandles$Lookup.checkMethod(java.base@9-ea/MethodHandles.java:1582)
at
java.lang.invoke.MethodHandles$Lookup.getDirectMethodCommon(java.base@9-ea/MethodHandles.java:1731)
at
java.lang.invoke.MethodHandles$Lookup.getDirectMethodNoSecurityManager(java.base@9-ea/MethodHandles.java:1725)
at
java.lang.invoke.MethodHandles$Lookup.unreflectSpecial(java.base@9-ea/MethodHandles.java:1336)
at
org.codehaus.groovy.vmplugin.v7.Java7.getInvokeSpecialHandle(Java7.java:96)
at
org.codehaus.groovy.runtime.ConversionHandler.invoke(ConversionHandler.java:109)
at com.sun.proxy.$Proxy47.reversed(Unknown Source)
at java_util_Comparator$reversed$0.call(Unknown Source)
at
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)
at
org.codehaus.groovy.runtime.InterfaceConversionTest.testDefaultInterfaceMethodCallOnProxy(InterfaceConversionTest.groovy:52)
my code uses MethodHandles.Lookup.PRIVATE only, which the implementation
no longer allows in this case. I had not yet time to investigate if
another mode works.
That's why i've written the Proxy2 library [2].
so the solutions are either you use the Proxy2 library (which doesn't work
with jdk9 yet) or we retrofit the interface InvocationHandler to take a
supplementary Lookup object.
regards,
Rémi
[1]
http://docs.oracle.com/javase/7/docs/api/java/lang/invoke/MethodHandles.Lookup.html#findSpecial%28java.lang.Class,%20java.lang.String,%20java.lang.invoke.MethodType,%20java.lang.Class%29
[2] https://github.com/forax/proxy2
what is the problem under jdk9?
Mostly the semantics of unsafe.defineAnonymousClass has changed so i have to
investigate if i can workaround that :(
ah that, right :(
bye Jochen