Feedback on proposal for #ReflectiveAccessToNonExportedTypes
Alan Bateman
Alan.Bateman at oracle.com
Sun Jul 10 07:51:16 UTC 2016
On 09/07/2016 12:22, Jochen Theodorou wrote:
>
> ok, let us assume I want to write a library that does what reflection
> can do today using bytecode generation. And let us assume I write a
> library, that will use this reflective module to call from private API
> to private API. How do we configure the two modules and what, besides
> the bytecode generation and the api, does the reflective library have
> to do (layers for example)? Would that have the same power as core
> reflection as far as the module system is concerned?
Just so I understand. There is code in module m1 that uses this library
to generate code to access something in module m2, is that right? Also
when you say "private API" then I think you mean the API is in a package
that is not exported by m2.
Assuming this is the scenario then I would expect the generated code to
fail because the the API is not accessible outside of m2. That is, the
code that the library generates (into m1?) will throw
IllegalAccessError. This is no different of course from what you have
with JDK 8 and older. Ignoring modules, if the secret API in m2 is a
non-public class then it's inaccessible to code in m1.
Module layers might be too much to bring into the discussion at this
point, esp. if m1 and m2 are in different layers with different class
loaders and you have to understand the visibility before getting to
accessibility.
As regards doing the equivalent with core reflection then it would be
exactly the same. Code in m1 using core reflection in an attempt to get
at the "private API" in m2 will fail with IllegalAccessException
(setAccessible is also too much to being into the discussion at this point).
> :
>
> Oh... and let us assume there are two modules using this reflective
> module configured to be able to access their hidden API using the
> reflective library. Would this automatically allow the two libraries
> to call into the other hidden library?
If the so-called hidden API is public and m2 exports the package with
that API to its friend m1 then it should work. I'm assuming here that
the library generating the code is generating it into m1. If it's
generating it into another module then it won't work of course, at least
not unless m1 exports the package (maybe reflectively) to that module.
My guess is that your mail will have follow-on discussion so it might be
better to start a new thread on jigsaw-devv so avoid it getting lost in
the #ReflectiveAccessToNonExportedTypes discussion.
-Alan.
More information about the jigsaw-dev
mailing list