Re: trySetAccessible​

Jochen Theodorou blackdrag at gmx.org
Mon Jul 10 09:44:30 UTC 2017



On 10.07.2017 10:07, Alan Bateman wrote:
[...]
> Remember the purpose of the warnings is to make you or your users aware
> that the code will behave differently when access to JDK internals, or
> other so-called illegal access, is denied.

In the past we did create a MetaClass, which contains all the accessible 
methods and properties. This meta class is used for method selection 
during invocation, it is used for querying and for runtime meta 
programming.

These warnings now force us to change the semantics and not show the 
accessible methods, but all methods. Invocation will then have to make 
it accessible... something we moved to meta class creation because it 
slows down the invocation mechanism. And then we will still get false 
warnings in reflective code.

Example:

module A:

class Foo {
   protected void foo(){}
}

Groovy program:

class X extends Foo {
   def bar() {return {foo()}}
}

if Foo is in an exported package, then it is legal for X to call foo, 
even though it is protected. But bar() does not directly call foo, it 
will do so in a Closure (not functional closure, not lambdas). In a 
Closure the implicit this has no fixed meaning and is realized as 
anonymous inner class. With our current protocol the call to foo ends up 
in the meta class logic, which then executes the method call. This will 
then cause a warning "WARNING: An illegal reflective access operation 
has occurred".

Now tell me how this is useful for the user. The call is supposed to be 
legal after all. Still we will get a warning. How am I supposed to tell 
our users about correct and wrong warnings?

Of course I am aware that I am supposed to give in a Lookup object and 
return a MethodHandle instead. But without changes to the MOP API this 
cannot be done. And that means Groovy 1.0 code will, for the first time 
in our history, no longer really work on a new Groovy version, once this 
change is done. And here I am not even sure that "giving in the Lookup 
object" is really what I should do. This Lookup object would have full 
access to X after all (I need to be able to call private methods too you 
know). And that does not sound right either

bye Jochen


More information about the jigsaw-dev mailing list