On 12/07/2016 10:28, Andrew Dinn wrote:

:
I think I need to ask you to clarify this as it doesn't seem to
recognise the point I was making. Of course, that may well indicate that
I have failed to understand the precise behaviour of exports dynamic.

Let us assume Module M exports dynamic P, where P is a package which
contains a public class C_pub and a non-public class C_pri (let's say it
is package-protected).

My understanding is that this means that:

Java source files for classes not in module M which import these classes
or reference them by name will suffer a compile-time error.
Correct. Also an error (IllegalAccessError) at run-time if you create the bytecode by other means (or maybe dropping the public modifier and not re-compiling the compiler for example).


References to the corresponding instances of class Class for C_pub or
C_pri may nevertheless be obtained by methods of classes not in Module M
at runtime (e.g. using a classloader lookup by name).
Correct. This is visibility and is not changed (try Class.forName to load C_Pri with JDK 8 and you'll see the same thing).


References to members of these classes (methods or fields) may be
obtained by methods of classes not in Module M (e.g. by using the public
API of Class).
Correct. However if you attempt access (Method::invoke, Field::get, Constructor::newInstance) then it will fail with IllegalAccessException (exactly the same as JDK 8 and older).


Calls to setEnabled(true) on those members will succeed even when the
calling method is not in class M (assuming the call is not invalidated
by the usual (mon-module) security restrictions)
I assume you mean setAccessible(true), the sledge hammer that breaks the door down by suppressing Java Language access checks. In this case, package P is exported, and so setAccessible(true) will succeed.


The latter is so irrespective of whether we are referring to class C_pub
or C_pri and irrespective of whether the member of C_pub or C_pri in
question is public or non-public.
If a library or framework really needs to get at types or members that aren't accessible then this is what it will typically too. There are sometimes better solutions with Lookup objects but maybe the discussion will go there. For now I assume we need to establish the basics.

-Alan

Reply via email to