Java Platform Module System
Alex Buckley
alex.buckley at oracle.com
Tue May 2 22:27:56 UTC 2017
On 5/2/2017 5:13 AM, Stephan Herrmann wrote:
> Thanks, Alex, for promising improvements in various places of the spec.
Re: Multiple packages with the same name can be "visible" (helpful
terminology for program analysis) but exactly one of these packages must
be identified as the meaning of the name. First, let's define what we want:
7.4.3 Package Observability and Visibility
...
A package is _uniquely visible_ to a module M if and only if either (i)
an ordinary compilation unit associated with M contains a declaration of
the package, and M does not read any other module that exports the
package to M; or (ii) no ordinary compilation unit associated with M
contains a declaration of the package, and M reads exactly one other
module that exports the package to M.
Then we can pick the "right" package to go with the name:
6.5.3.1 Simple Package Names
If a package name consists of a single Identifier, then the identifier
must occur in the scope of exactly one declaration of a top level
package with this name (§6.3), and that package must be uniquely visible
to the current module (§7.4.3), or a compile-time error occurs. The
meaning of the package name is that package.
6.5.3.2 Qualified Package Names
If a package name is of the form Q.Id, then Q must also be a package
name. The package name Q.Id names a package that is the member named Id
within the package named by Q. If Q.Id does not name a package that is
uniquely visible to the current module (§7.4.3), then a compile-time
error occurs.
(Note that 6.5.3.2 did not, and does not, recurse into 6.5.3.1 when the
Q in the qualified name Q.Id is simple. 6.5.3.1 relies on scope, which
means it applies only when someone has a declaration of a top level
package, but plainly 6.5.3.2 has always been able to give meaning to the
name P.Q based on a declaration of 'package P.Q;' -- no-one needed to
declare a top level 'package P;'. The 6.5.3.2 phrase "Q must also be a
package name" in JLS8 was a trailer for the phrase about Q being an
observable package, and in JLS9 is a trailer for the phrase about Q.Id
being a uniquely visible package.)
> I recall several threads on this list ending in you saying "still being
> clarified" [1][2]. Are those issues settled by now and just need to be
> penned down? Otherwise it would be very helpful just to see the list of
> open questions, so we don't bang our heads against walls that are still
> subject to change (I'm not speaking about the general "Issue Summary",
> but s.t. more focused on JLS and its dependencies in JPMS spec).
>
> Looking forward to an updated spec version, allowing us to double check
> if those changes raise any follow-up questions,
> Stephan
>
> [1]
> http://mail.openjdk.java.net/pipermail/jigsaw-dev/2017-January/010866.html
This was about multiple packages with the name P being visible at once.
So that's covered by the "uniquely visible" invocation in package names.
> [2]
> http://mail.openjdk.java.net/pipermail/jigsaw-dev/2017-March/011544.html
The open question there was about multiple modules, directly required by
a root module, containing the same package, but without any exports that
would cause any module to see a split package. This module graph is
legal, so it will resolve in JPMS; the JLS defers to that.
javac gives a lint warning (on-by-default, suppressible) if the modules
being compiled cannot be mapped to the boot layer.
Alex
More information about the jigsaw-dev
mailing list