jbonofre commented on code in PR #741:
URL: https://github.com/apache/camel-karaf/pull/741#discussion_r3907732965
##########
core/camel-core-osgi/src/main/java/org/apache/camel/karaf/core/OsgiFactoryFinder.java:
##########
@@ -79,23 +87,51 @@ public Optional<Class<?>> findClass(String key) {
// NOTE, the first found factory will be return
public BundleEntry getResource(String name) {
BundleEntry entry = null;
- Bundle[] bundles;
+ // only allocated when more than one bundle provides the same
descriptor, which is not the normal case
+ List<Bundle> alsoProviding = null;
- bundles = bundleContext.getBundles();
+ Bundle[] bundles = bundleContext.getBundles();
- URL url;
for (Bundle bundle : bundles) {
- url = bundle.getEntry(getResourcePath() + name);
+ URL url = bundle.getEntry(getResourcePath() + name);
if (url != null) {
- entry = new BundleEntry();
- entry.url = url;
- entry.bundle = bundle;
- break;
+ if (entry == null) {
+ entry = new BundleEntry();
+ entry.url = url;
+ entry.bundle = bundle;
+ } else {
+ if (alsoProviding == null) {
+ alsoProviding = new ArrayList<>();
+ }
+ alsoProviding.add(bundle);
+ }
}
}
+ if (alsoProviding != null) {
+ // the scan order is the container's bundle install order, so
which bundle wins is not something
+ // the operator chose. Say so rather than resolving silently:
during a rolling upgrade with two
+ // versions of a bundle installed side by side, this is how a
patched bundle gets ignored. The
+ // result is also cached per key by findClass, so the choice made
here is sticky.
+ LOG.warn("Factory descriptor {} is provided by more than one
bundle. Using the one from {},"
Review Comment:
Confirmed, and it is a guaranteed false positive rather than a possible one
— the two bundles ship *different* implementations:
- `camel-xml-io` → `class=org.apache.camel.xml.LwModelToXMLDumper`
- `camel-xml-jaxb` → `class=org.apache.camel.xml.jaxb.JaxbModelToXMLDumper`
and both are in the default `camel-core` feature (`camel-features.xml:285`
and `:288`). So a stock install would warn at every startup.
Dropped the WARN. Note the same ambiguity exists in flat-classpath Camel,
where classpath order picks the winner — it is upstream, not a Karaf artifact.
Trimming one of the two bundles from the `camel-core` feature is a separate
discussion; since they provide different dumpers it is a behaviour change, not
just a dedup.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]