Proposal: #ReflectiveAccessToNonExportedTypes (revised) & #AwkwardStrongEncapsulation: Weak modules & private exports

Jochen Theodorou blackdrag at gmx.org
Wed Sep 21 12:29:45 UTC 2016



On 21.09.2016 13:53, David M. Lloyd wrote:
[...]
> It turns out that you don't actually need setAccessible to access a
> superclass protected method from a subclass.

I can even override a non-final protected method and make it public, yes.

> If you have an instance of a subclass of the type containing the
> protected method, any class in the _same package_ as the _subclass_ can
> call invoke() on a Method without first making it accessible, as long as
> you pass in that subclass instance (even if the method is static, which
> is a little weird but necessary to make the check work!).

This will not work if the instance is not created by me

> As to whether this makes sense in 100% of cases... that's a different
> discussion (and a fairly complex one at that - the code for checking
> protected access is (AFAICT) the most complex part of access checking in
> the JDK and the JVM).

and has many rules I did learn of quite late, yes.

bye Jochen


More information about the jigsaw-dev mailing list