The explanation is kind of long, but the code issue I found is simple, please look at the linked PR.
Most of the text will be about what I have attempted, in hopes of getting any comment on what I'm trying to archieve:
I have a bean implementing ContainerRequestFilter that I'm obtaining through OSGI, and this bean has a @Context injected field. All of the bundles in my application are setting this bean as a Provider via JAXRS.
At first, the @Context annotation was used directly on the field of the implementing class. This caused the injection to fail on all bundles trying to use it, because it seems the imported object via osgi was a Proxy rather than the actual original bean that was exported. CXF attempted to look for any field to inject, but the Proxy never exposed anything of the underlying object.
The next attempt was putting the @Context annotation on the setter method in a new interface the filter is now implementing.
Now, the first bundle works properly, but then fails as described in the title of this issue: After the second bundle is deployed, trying to call any method of the injected field when handling the first endpoint (from the first bundle) will throw an NPE (the field itself isn't null tho)
Digging through the code, I can see that a ThreadLocal proxy in combination with a map are being used for the injection.
And that each endpoint can re use the same ThreadLocal proxy as long as CXF can retrieve it from the provider bean.
Finally, I added a getter method for the injected field, but the problem persisted. The linked PR fixes InjectionUtils#getGetterFromSetter so this problem goes away.
I wanted to also ask. Is this a good approach for reusing the filter through OSGI?