On 11/04/2018 21:07, Rafael Winterhalter wrote:
I do not think that this is possible. If the module containing the interface does not open a package, I cannot change the privileges of the main module such that I can resolve a method handle for invoking the special invocation.

I just tried this out too and I did not find a way, could you suggest how to change my code for being able to do so?
If the interface is public in an exported package (no need for the package to be open) then the proxy will be generated into the unnamed module. So easy to get a Lookup to the proxy class and you can use this as the special caller. Can you change your invocation handler to the following and try it:

Class<?> proxyClass = proxy.getClass();
Main.class.getModule().addReads(proxyClass.getModule());
Lookup lookup = MethodHandles.privateLookupIn(proxyClass, MethodHandles.lookup());
MethodType mt = MethodType.methodType(String.class);
return lookup.findSpecial(iface, "foo", mt, proxyClass).bindTo(proxy).invokeWithArguments();

-Alan

Reply via email to