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 .
- csr of
-
JDK-8193302 Javac AssertionError: typeSig ERROR on usage of @Generated
-
- Closed
-