Me trying to explain the problem behind #ReflectiveAccessToNonExportedTypes
Stephane Epardaud
stef at epardaud.fr
Wed Jul 20 15:24:59 UTC 2016
On 20/07/16 16:33, mark.reinhold at oracle.com wrote:
> Requiring something to be declared explicitly one way or the other,
> rather than offer a safe and sensible default, seems very unlike the
> rest of the language.
I have to say I agree with that, even though I also understand the
problem that non-public packages will cause to adopters (which is why I
proposed a meta-annotation solution to _some_ cases).
The default visibility should indeed be (module-)private, that's what it
is for regular Java declarations, and that's what it should be for
packages now that they can have visibility.
Even if we required that package declarations (in package-info.java) now
be declared with `public` modifiers for that (rather than in the module
descriptor), it would _still_ cause existing packages to become
non-exported when you convert your jar into a module.
If you don't convert your jar to a module all your packages remain
exported. If you do, you have to do _something_ to your packages
whatever solution you pick.
You can say that they should be exported by default, so that existing
applications using reflection keep working, but that's really a bad
default. Sometimes backwards-compatibility requires compromises and
introducing bad defaults, but in this case you already have to do the
manual step of adding a module descriptor, so at this point it is not
unreasonable to have the good default of non-exported modules and teach
people that when they add a module descriptor they also have to decide
and explicitly state which packages to export.
Now, granted I'm already used to that in both Ceylon and OSGi, so
perhaps I'm biased.
More information about the jpms-spec-observers
mailing list