Closed tjwatson closed 5 months ago
From our discussion:
The fragment in particular causes problems due to the need to re-resolve it if a feature which depends on the CDI API feature is started and then the CDI feature is started later, but the issues run a little deeper than this.
The CDI API has two places where an API class needs to have access to an instance from the implementation: CDI
(which holds a reference to a CDIProvider
instance) and BuildServicesResolver
(holds BuildServices
).
For BuildServicesResolver
, the BuildServices
instance is only loaded once. If the CDI feature is enabled, then disabled, then re-enabled, the CDI implementation bundles will be installed a second time, so we should be using a new instance of BuildServices
. Continuing to use the old one is likely to eventually result in ClassCastExceptions
when new and old classes mix, or if the old version of the class has stale references which no longer work.
Ideally, we either need the API to allow us to unset and re-set the instance when the CDI feature is stopped and started, or we need to set an instance which dynamically delegates to the real instance.
Related to #26599
The CDI 4.0 feature has a host bundle
io.openliberty.jakarta.cdi.4.0
that is included in a private featureio.openliberty.jakarta.cdi-4.0
. This feature is included in some other features that need the API for CDI but do not want to enable the full CDI implementation. The issue is when the public cdi-4.0 feature is enabled dynamically when the private featureio.openliberty.jakarta.cdi-4.0
is already enabled then the fragmentio.openliberty.cdi.4.0.internal.services.fragment
bundle cannot resolve dynamically. This is a limitation of OSGi because the fragment introduces a new requirement for the imported packageorg.jboss.weld.lite.extension.translator
.PR #26599 forces the host to re-resolve (stop/refresh/start) so it gets a new classloader. This will cause loads of other bundles to also get refreshed in the chain of dependencies on CDI. This should "just work" but other parts of the system seem to hold onto stale references which leads to class cast exceptions like the following:
Seems something down in the webcontainer security is holding onto stale references when the CDI API bundles are refreshed. While that could be addressed it may be best to figure out if the CDI implementation can be installed dynamically without forcing the host CDI API bundle to be refreshed.