[module-imports] Importing java.se?
Jan Lahoda
jan.lahoda at oracle.com
Fri Jul 12 13:27:01 UTC 2024
On the first error, as of JDK 11 (IIRC), the additional root modules for
(the) unnamed module are system modules which have an unqualified
exports (please see JDK-8197532 for more precise and exact details). So,
when compiling code in the unnamed module, java.se, which does not have
any exports, is usually not in the module graph, and hence is not read
by the unnamed module. If java.se is added to the root modules using
`--add-modules java.se` (for an unnamed module), or via a requires (in
case of named modules), then it should be possible to "import module"
from it.
Jan
On 12. 07. 24 14:27, Tagir Valeev wrote:
> Hello!
>
> I'm playing with module imports and tried to import java.se
> <http://java.se> module:
>
> import module java.se <http://java.se>;
>
> class Test {
> void main() {
> ArrayList<String> list;
> }
> }
>
> Building (23-ea+31-2337) yields the following errors:
>
> >\jdks\jdk-23\bin\java.exe --enable-preview --source=23 Test.java
> Test.java:1: error: unnamed module does not read: java.se <http://java.se>
> import module java.se <http://java.se>;
> ^
> Test.java:5: error: cannot find symbol
> ArrayList<String> list;
> ^
> symbol: class ArrayList
> location: class Test
> 2 errors
> error: compilation failed
>
> I'm not sure I understand the first error "unnamed module does not
> read". Importing java.se <http://java.se> is described in JEP 476 text
> [1], so I assume that it's something allowed. Is the current behavior
> intended? If yes, then the JEP text should probably not mention
> java.se <http://java.se> as an allowed example to import.
>
> The second error is caused by the fact that java.se <http://java.se>
> does not declare explicitly that it transitively requires java.base.
> It's assumed that any module requires java.base implicitly, and
> requires transitive java.base declaration is not allowed. However,
> this looks strange with java.se <http://java.se> specifically: we can
> import the whole Java SE platform via a single import declaration
> _except_ the java.base module. Contrary, running jshell JAVASE imports
> the whole Java SE platform including the java.base module. This looks
> inconsistent to me.
>
> So the question is: is it actually allowed to import java.se
> <http://java.se>, and should it import java.base automatically?
>
> With best regards,
> Tagir Valeev
>
> [1] https://openjdk.org/jeps/476
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-spec-observers/attachments/20240712/29586af2/attachment-0001.htm>
More information about the amber-spec-observers
mailing list