Spec confusion about open modules

Alan Bateman Alan.Bateman at oracle.com
Sun Jul 2 20:36:53 UTC 2017


On 02/07/2017 11:16, Cay Horstmann wrote:
> In §7.7, the JLS draft from 2017-06-26 states:
>
> An open module, with the open modifier ... grants access at run time to
> types in all its packages, as if all packages had been exported.
> ...
> Distinct from access at compile time and access at run time, the Java 
> SE Platform provides reflective access via the Core Reflection API 
> (§1.4)...
>
> So, here is my question. I had thought the purpose of open modules and 
> opened packages was to be able to access non-public members at runtime 
> through reflection.
>
> But it appears from the workding of the JLS as if other runtime access 
> would also be possible. Like what? I mean, if I don't have 
> compile-time access, what runtime access do I have other than through 
> reflection? Synthesized byte codes? Method handles? Or did I overlook 
> something really obvious here?
As it says, an open module grants access at run time to types in all of 
the module's packages, as if all packages are exported. This means 
bytecode or reflection can be used to access the public classes / public 
members in all packages. In addition, the reflection APIs (with 
setAccessible or MethodHandles.privateLookupIn) allow for "deep 
reflection" so you can reflect on all members of all classes in all 
packages.

-Alan


More information about the jigsaw-dev mailing list