[module-imports] Importing java.se?

Tagir Valeev amaembo at gmail.com
Fri Jul 12 12:27:38 UTC 2024


Hello!

I'm playing with module imports and tried to import java.se module:

import module 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
import module 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 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 as an allowed example to import.

The second error is caused by the fact that 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
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, 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-experts/attachments/20240712/ac52faeb/attachment.htm>


More information about the amber-spec-experts mailing list