jbonofre opened a new pull request, #752:
URL: https://github.com/apache/camel-karaf/pull/752
Backport of #741 to `camel-karaf-4.18.x`. Fixes #733 on that branch.
## What
`OsgiFactoryFinder.getResource` walks `bundleContext.getBundles()` and
returns
the first bundle with a matching factory descriptor.
`getBundles()` returns a **snapshot**, and per the OSGi spec
`Bundle.getEntry()`
throws `IllegalStateException` once a bundle has been uninstalled. So a
`feature:uninstall` or `bundle:update` running concurrently with a resolution
can make the scan throw on a bundle that has nothing to do with the factory
being looked up.
What turns that transient race into a lasting failure is the caching in
Camel.
`findClass` calls `getResource` from inside
`DefaultFactoryFinder.addToClassMap`,
whose mapping function stores the exception in `classesNotFoundExceptions`
and
rethrows it on every later lookup of the same key. `IllegalStateException`
is an
`Exception`, so the key stays broken for the life of the context, until
`clear()`.
## How
- Skip bundles already in state `Bundle.UNINSTALLED`.
- Treat an `IllegalStateException` from `getEntry` as "this bundle has no
such
entry" and continue, rather than letting it fail the whole scan. This
covers
the bundle that is uninstalled between the state check and the call.
- Log at DEBUG which bundle supplied the descriptor, so an operator with
several
providers installed can tell which one is actually in use.
**Selection is unchanged.** The scan still `break`s at the first match, so
install order still decides and there is no added cost on a path that is
walked
once per key.
## Cherry-pick
Clean cherry-pick of e784cd910bd576dd5dfc9505286377ac70053fb3, no conflicts
and
no adaptation needed — `OsgiFactoryFinder.java` was identical on both
branches.
## Tests
`OsgiFactoryFinderTest` (new): no provider, single provider, first-match-wins
with several providers, an `UNINSTALLED` bundle never being asked for an
entry,
and a bundle uninstalled mid-scan not failing the lookup.
```
Tests run: 6, Failures: 0, Errors: 0, Skipped: 0 -- OsgiFactoryFinderTest
Tests run: 8, Failures: 0, Errors: 0, Skipped: 0 --
OsgiDefaultCamelContextTest
Tests run: 4, Failures: 0, Errors: 0, Skipped: 0 -- OsgiTypeConverterTest
```
--
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]