gansheer opened a new issue, #9421:
URL: https://github.com/apache/camel-quarkus/issues/9421

   ### Bug description
   
   > Split out of #6926.
   
   A CDI bean implementing a Camel SPI type without `@Named`/`@Identifier` is 
never installed on the Camel context in the first place. `UnitOfWorkFactory` is 
one example, but the same applies to other SPI types resolved through 
`DefaultConfigurationConfigurer`.
   
   Camel resolves it through 
`DefaultConfigurationConfigurer.getSingleBeanOfType(registry, 
UnitOfWorkFactory.class)`, which needs exactly one entry from 
`Registry#findByTypeWithName`. Since 3.26.0 (and the 3.20.3 backport), 
`RuntimeBeanRepository.findByTypeWithName` drops every bean that has neither 
`@Named` nor an `@Identifier` qualifier:
   
   ```java
   String name = resolveBeanName(instanceHandle.getBean());
   if (ObjectHelper.isNotEmpty(name)) {
       beans.put(name, instanceHandle.get());
   }
   ```
   
   That guard comes from #7559, whose actual fix was the `@Identifier` fallback 
in `resolveBeanName` (the null-key issue from #7558). The side effect is that 
unnamed CDI beans are no longer exposed by type, so `getSingleBeanOfType` sees 
an empty map and a custom `UnitOfWorkFactory` is silently ignored. In a local 
reproduction, simply adding `@Named` to the factory makes it work.
   
   @jamesnetherton was dropping unnamed beans intended in #7559, or a 
consequence of avoiding `null` map keys? `BeanRepository#findByTypeWithName` 
says entries are keyed by bean id, so falling back to 
`InjectableBean.getIdentifier()` when there is no name would keep the #7558 fix 
intact and restore the pre-3.26 behaviour:
   
   ```java
   return ObjectHelper.isNotEmpty(name) ? name : bean.getIdentifier();
   ```
   
   I'm wondering if it is a good idea to make this change. On one side the 
current behaviour is a silent failure. On the other side with the change 
unnamed beans of ~30 SPI types start applying, and named+unnamed pairs now 
resolve to Camel's default.
   
   The proposed code fix is not the only option; `getSingleBeanOfType` could 
fall back to `Registry#findByType` when the name-keyed map is empty or 
ambiguous. That would fix this class of bug for every registry, not just CDI, 
but it is a Camel core change on Camel's version. A doc-only "beans used as 
Camel SPIs must carry @Named" is the cheapest alternative, but it just leaves 
the issue in place. WDYT @jamesnetherton ?
   
   Affected versions: Since 3.26.0 (and the 3.20.3 backport)


-- 
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]

Reply via email to