<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<br>
On 17/04/2023 15:20, Rob Bygrave wrote:<br>
<blockquote type="cite" cite="mid:CAC=ts-HzDhiDb9DgX=0cc-Mt0jFBtpEtqypvPMFUC5mEfPkFFA@mail.gmail.com">
<div dir="ltr"><i>:</i>
<div><span style="color:rgb(23,43,77);font-family:"DejaVu
Sans",sans-serif;font-size:14px"><br>
</span></div>
<div><span style="color:rgb(23,43,77);font-family:"DejaVu
Sans",sans-serif;font-size:14px"><br>
</span></div>
<div><span style="color:rgb(23,43,77);font-family:"DejaVu
Sans",sans-serif;font-size:14px">> </span><i><span style="color:rgb(23,43,77);font-family:"DejaVu
Sans",sans-serif;font-size:14px">is it reasonable to
consider that ServiceLoader is the *only* vector by which
the implementation class will be instantiated?<span class="gmail-Apple-converted-space"> </span></span></i></div>
<div><span style="color:rgb(23,43,77);font-family:"DejaVu
Sans",sans-serif;font-size:14px"><br>
</span></div>
<div><span style="color:rgb(23,43,77);font-family:"DejaVu
Sans",sans-serif;font-size:14px">In my view this is
expected and imo I get there by thinking in the opposite
direction from the provides p.S type to the requires static
rather than the other way around. That is, the p.S type is
only available via requires static hence it is expected to
potentially not exist at runtime in the module-path. That
is, if p.S was expected to exist at runtime it would be
"read" via a requires or requires transient clause and not
via a requires static - <i>the use of requires static for
this case is explicit and intentional</i>. </span></div>
<div><span style="color:rgb(23,43,77);font-family:"DejaVu
Sans",sans-serif;font-size:14px"><br>
</span></div>
<div><span style="color:rgb(23,43,77);font-family:"DejaVu
Sans",sans-serif;font-size:14px">In using requires
static ... imo we are explicitly going out-of-our-way to say
"the types here might not be available at runtime" and the
classic case for this as I see it is this case of providing
an optional service, that will only be service loaded if the
user of that service is in the classpath / module-path. <i>IF</i>
the module that is the user of a service is in the classpath
/ module-path then that module will ensure that the p.S type
is in the module-path.</span></div>
<br>
</div>
</blockquote>
<br>
In your example, module io.avaje.config declares that it provides an
implementation of <span style="font-variant-ligatures:no-common-ligatures">io.avaje.inject.spi.PropertyRequiresPlugin.
There is nothing to connect this to </span><span style="font-variant-ligatures:no-common-ligatures"><span style="font-variant-ligatures:no-common-ligatures">`requires
static </span><span style="font-variant-ligatures:no-common-ligatures"><span style="font-variant-ligatures:no-common-ligatures">io.avaje.inject`.
The module system would need to search "far and wide" for </span></span></span><span style="font-variant-ligatures:no-common-ligatures"><span style="font-variant-ligatures:no-common-ligatures"><span style="font-variant-ligatures:no-common-ligatures"><span style="font-variant-ligatures:no-common-ligatures"><span style="font-variant-ligatures:no-common-ligatures"><span style="font-variant-ligatures:no-common-ligatures">io.avaje.inject
to see if exports </span></span></span></span></span></span><span style="font-variant-ligatures:no-common-ligatures"><span style="font-variant-ligatures:no-common-ligatures"><span style="font-variant-ligatures:no-common-ligatures"><span style="font-variant-ligatures:no-common-ligatures"><span style="font-variant-ligatures:no-common-ligatures"><span style="font-variant-ligatures:no-common-ligatures"><span style="font-variant-ligatures:no-common-ligatures">io.avaje.inject.spi
</span></span></span></span></span></span></span><span style="font-variant-ligatures:no-common-ligatures"><span style="font-variant-ligatures:no-common-ligatures"><span style="font-variant-ligatures:no-common-ligatures"><span style="font-variant-ligatures:no-common-ligatures"><span style="font-variant-ligatures:no-common-ligatures"><span style="font-variant-ligatures:no-common-ligatures"><span style="font-variant-ligatures:no-common-ligatures">to
io.avaje.config, otherwise there is no way for it to
know that the "missing package" is in a module that is
not required to be present at run-time. In other
words, </span></span></span></span></span></span></span><span style="font-variant-ligatures:no-common-ligatures"><span style="font-variant-ligatures:no-common-ligatures"><span style="font-variant-ligatures:no-common-ligatures"><span style="font-variant-ligatures:no-common-ligatures"><span style="font-variant-ligatures:no-common-ligatures"><span style="font-variant-ligatures:no-common-ligatures"><span style="font-variant-ligatures:no-common-ligatures"><span style="font-variant-ligatures:no-common-ligatures"><span style="font-variant-ligatures:no-common-ligatures">`requires
static </span><span style="font-variant-ligatures:no-common-ligatures"><span style="font-variant-ligatures:no-common-ligatures">io.avaje.inject` does
not convey to the module system that </span></span></span></span></span></span></span></span></span></span><span style="font-variant-ligatures:no-common-ligatures"><span style="font-variant-ligatures:no-common-ligatures"><span style="font-variant-ligatures:no-common-ligatures"><span style="font-variant-ligatures:no-common-ligatures"><span style="font-variant-ligatures:no-common-ligatures"><span style="font-variant-ligatures:no-common-ligatures"><span style="font-variant-ligatures:no-common-ligatures"><span style="font-variant-ligatures:no-common-ligatures"><span style="font-variant-ligatures:no-common-ligatures"><span style="font-variant-ligatures:no-common-ligatures"><span style="font-variant-ligatures:no-common-ligatures"><span style="font-variant-ligatures:no-common-ligatures"><span style="font-variant-ligatures:no-common-ligatures"><span style="font-variant-ligatures:no-common-ligatures"><span style="font-variant-ligatures:no-common-ligatures"><span style="font-variant-ligatures:no-common-ligatures"><span style="font-variant-ligatures:no-common-ligatures"><span style="font-variant-ligatures:no-common-ligatures"><span style="font-variant-ligatures:no-common-ligatures">
</span><span style="font-variant-ligatures:no-common-ligatures"><span style="font-variant-ligatures:no-common-ligatures">io.avaje.inject </span></span></span></span></span></span></span></span></span></span></span></span></span>exports
packages with service types.<br>
<br>
I understand there is a temptation to compare
`requires static` with optional dependences in Maven
but they are not the same thing. `requires static` is
more for use-cases like annotations that do not need
to be present at run-time. It could of course be
extended but it's a slippery slope that ultimately
amounts to giving up on reliability. In this case, it
amounts to giving up on a post resolution check and
allowing all service providers to have a dangling
reference to a service type.</span></span></span></span></span></span></span><br>
<br>
-Alan<br>
</body>
</html>