provides and requires static ... runtime error

Rob Bygrave robin.bygrave at gmail.com
Mon Apr 17 13:14:21 UTC 2023


I'm seeing a runtime error I was not expecting.


*Error occurred during initialization of boot
layerjava.lang.module.ResolutionException: Module io.avaje.config does not
read a module that exports io.avaje.inject.spi*


The module io.avaje.config has a requires static io.avaje.inject , and
that io.avaje.inject module exports the interface used in the provides
clause.

module io.avaje.config {


  ...

  requires static io.avaje.inject;

  ...

  provides io.avaje.inject.spi.PropertyRequiresPlugin with
io.avaje.config.InjectPropertiesPlugin;

}


When a module is run with module-path without the io.avaje.inject module
then the error above occurs at runtime when the module is run using Java 20
(build 20+36-2344).

So reading
https://docs.oracle.com/javase/9/docs/api/java/lang/module/package-summary.html

We see:

*If any of the following conditions occur in the readability graph, then
resolution fails *

*- **A module M declares that it 'uses p.S' or 'provides p.S with ...' but
package p is neither in module M nor exported to M by any module that M
"reads"*

So requires *static* io.avaje.inject means it does not "read"
io.avaje.inject. To me that suggests we are effectively unable to use
requires *static* for a provides type (it will compile successfully but we
will observe runtime errors if the optional module is indeed not in the
module-path).

Have I missed something obvious? Is there any way to use a requires static
with the provides type/package to provide a service that can optionally be
used (based on if the module that exports the provides type is in the
module path)? This works fine with classpath obviously.


Thanks, Rob.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/jigsaw-dev/attachments/20230418/0e8363ba/attachment.htm>


More information about the jigsaw-dev mailing list