[External] : Re: Inconsistency with service loading by layer or by class loader
Alan Bateman
alan.bateman at oracle.com
Wed Dec 18 09:55:00 UTC 2024
On 17/12/2024 17:21, David Lloyd wrote:
> :
>
> I was using it as more of an example about how a thing may be possible
> and allowed by the platform, and thus is achievable, yet not
> specifically presented with a convenient API. That said, I've opened
> https://bugs.openjdk.org/browse/JDK-8346439 as a way to continue the
> discussion, framed as a specific feature request which covers what we
> need, and it does in fact include an `addUses` method.
We decided in 2017 to not add these methods. I've trying to see if there
is any new insight that would motivate adding these methods now.
ML.Controller::addUses would be a no-op for an automatic module so this
method will only add a "uses" edge for an explicit module.
If the module has been compiled with references to the service class and
is calling ServiceLoader.load with that service class then its module
descriptor should have the appropriate `uses` in the module-info
already. Has the module author neglected to add this, didn't test, and
the ML.Controller method will be used to fix this?
The other scenario, and the motivation for Module::addUses, is where the
service is not known at compile-time, maybe code in the module is doing
service loading on behalf of another module. In that case, code in the
module itself should be calling Module::addUses method to add the
transient `uses` edge. Maybe the module author is not calling
Module:;addUses and the ML.Controller method will be used to fix that?
ML.Controller::addProvides is also puzzling. A service provider module
can only be compiled if the provider class is in the module and the
service class is accessible to it. Has the module author neglected to
add the `provides` and the ML.Controller method will be used to fix this?
Or maybe this is about instrumentation or code generation where the
container adds a provider implementation to the module? In that case,
why didn't the container augment the module-info at the same time? Maybe
the code generation to add the provider implementation happens after the
module has been loaded?
Finally, just to say that your prototype addProvides doesn't specify any
validation. It looks like it can be used to add any random class and
implementation class. If a method were to be added then it would
minimally need to check that the implementation class is in the module
and that it extends the service class.
-Alan.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/jigsaw-dev/attachments/20241218/5a138115/attachment.htm>
More information about the jigsaw-dev
mailing list