JDK-8204534 : javac should reject packages whose names are prefixes of names of uniquely visible packages
  • Type: CSR
  • Component: tools
  • Sub-Component: javac
  • Priority: P3
  • Status: Closed
  • Resolution: Approved
  • Fix Versions: 11
  • Submitted: 2018-06-07
  • Updated: 2018-06-12
  • Resolved: 2018-06-12
Related Reports
CSR :  
Description
Summary
-------

For type-import-on-demand, javac accepts not-uniquely visible packages whose names are prefixes of names of uniquely visible packages. This contradicts JLS 9 ��7.5.2, which requires the package named in type-import-on-demand to be uniquely visible.

Problem
-------

javac is not in sync with JLS 9 ��7.5.2. In particular, javac accepts imports like:

import java.*;

even though package "java" is not uniquely visible.

Solution
--------

For programs compiled with -source >= 9, javac will issue an error if the package named in the type-import-on-demand is not uniquely visible, as per JLS 9 ��7.5.2. Javac will continue accepting those programs if compiled with -source < 9

Specification
-------------

From JLS 9 ��7.5.2:

It is a compile-time error if the named package is not uniquely visible to the current module (��7.4.3), or if the named type is not accessible (��6.6).

From JLS 9 ��7.4.3:
A package is uniquely visible to a module M if and only if one of the following holds:

 - 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 .
 - 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 .

Comments
I note that a release note is already planned for this change. Moving to Approved.
12-06-2018