It's not too late for access control

John Rose john.r.rose at oracle.com
Tue Jul 12 16:00:08 UTC 2016


On Jul 12, 2016, at 8:01 AM, Paul Benedict <pbenedict at apache.org> wrote:
> 
> All things being equal with Jigsaw features today, I'd rather have "public"
> retain it's global visibility and extend "package private" to the module.

Again, $0.02, with apologies in advance for opining on a subject I'm not
an expert in.

From a pure language POV I find this appealing, but in our world there
are myriads of existing public classes already coded in libraries which need
large-scale encapsulation.  Surely we need to be able to tell some libraries,
"Hey, not so public, there; we're restricting your visibility."  If we can't do that
we don't have modules at all.  If Java had modules from the start, maybe
we'd say "public is globally public, so any class can punch through all layers of
encapsulation by using the super-strong keyword 'public', and the default
is 'module'."  (Advance apology if this is a straw-man.)

> This makes great sense to me. Why? Because when I develop a library, I
> really don't see any great benefit in hiding a type from another package.
> Let me qualify that.... I really don't see any great benefit in hiding a
> type from another package **that I own!** (double emphasis). I have
> inspected all my uses of "package private" and it always comes down to one
> thing: preventing static linkage to the type from packages **outside my
> library**.

To me this looks like a simple power struggle between the class author
expecting a platform for full publicity, and the system assembler expecting
to be able to control inter-library visibility.  Both can't have the final word.
Shouldn't the assembler have it?  And if the assembler is given absolute
control over some unit of access control, it seems likely to me that this
unit has to look a lot like a Jigsaw module.

Note that system assemblers cannot be expected to edit individual classes.
That would be another scale error.  So in the end, the author of a class and
of a package has to provide a provisional, local spec. of what's visible, while
the assembler (who works with unmodifiable libraries) owns the global spec.

(HTH.  I'm probably missing a couple of Third Way options; please point them
out.  I'll go back to lurk mode now.)

— John


More information about the jigsaw-dev mailing list