Are non-compilation units in the unnamed package of a named module open?

Thomas Zimmermann :

I could not find any mention of this in the JLS, it only talks about how compilation units are placed in the unnamed module when they are in the unnamed package.

Background: Many libraries require user code to put a configuration file with a specific name in the unnamed (default) package. I want to know if the JLS guarantees that these resources can be found via ClassLoader::getSystemResourceAsStream when using modules. It seems to work, but I'd like to have a source.

It would make sense, because there is no syntax for opens "", so the only way to be explicit would be to open the module itself.

Michael :

I think it's pretty clear.

An unnamed module exports every package whose ordinary compilation units are associated with that unnamed module.

An unnamed module opens every package whose ordinary compilation units are associated with that unnamed module.

Regarding the association:

The host system must associate ordinary compilation units in an unnamed package with an unnamed module (§7.7.5), not a named module.

Source

Note: it is talking about exporting the package, not exporting the compilation units, so resources in the package are covered by this statement.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326649&siteId=1