On 01.06.2016 18:57, Peter Levart wrote:
[...]
Anyway... the groovy runtime would be almost something like java.base,
but instead of being like a root element, this one will have to sit in
the middle, because we depend on java as well.
If that is true, then perhaps there is a simpler solution that doesn't
require modifying the exports of any module.
Make your TheInvoker take another argument of type MethodHandles.Lookup:
public class TheInvoker{
public static Object invoke(MethodHandles.Lookup lookup, Object
receiver, String name, Object... args) throws Throwable {
Method m = receiver.getClass().getDeclaredMethod(name,
toClass(args));
MethodHandle mh = lookup.unreflect(m).bindTo(receiver);
return mh.invokeWithArguments(args);
}
...
}
Then pass the appropriate lookup to it from where you call
TheInvoker.invoke (from MyOtherLib):
TheInvoker.invoke(MethodHandles.lookup(), receiver, "methodName",
arguments...);
receiver.getClass().getDeclaredMethod would fail, if I cannot access
the class of the receiver.
No, for obtaining reflection objects you don't need language access
rights. You need security permissions if security manager is installed,
but that's independent of language access checks. Language access checks
are performed when you call Method::invoke or Field::get, etc... or when
you do Lookup::unreflect, but the later is performed against the "caller
class" that is captured inside the Lookup object.
I was more thinking about modules here... well... now I am indeed
confused. I thought I did see that module access rules are enforced, but
I cannot find anything of that right now. So how does the module system
enforce the module system at runtime? I mean if that is not the case,
then why do I even need someething like Module#addReads? But the only
part where I can see that happening right now is for setAccessible...
bye Jochen