[ 
https://issues.apache.org/jira/browse/CAMEL-13948?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18151605#comment-18151605
 ] 

Claus Ibsen commented on CAMEL-13948:
-------------------------------------

`SimpleRegistry` keeps the beans of a name in a `LinkedHashMap`. A lookup by a 
super type returns the first matching
bean in bind order, so the result depends on how the beans were bound and is 
the same on every run. Binding several
beans of related types under the same name is an advanced corner case, as said 
earlier. Changing the registry
contract for it is not worth the risk, so closing this ticket.

_Claude Code on behalf of davsclaus_

> Unpredictable registry lookup
> -----------------------------
>
>                 Key: CAMEL-13948
>                 URL: https://issues.apache.org/jira/browse/CAMEL-13948
>             Project: Camel
>          Issue Type: Improvement
>          Components: camel-core
>            Reporter: Luca Burgazzoli
>            Priority: Minor
>             Fix For: Future
>
>
> The camel registry support binding multiple classes to the same entry via the 
> bind method:
> {code:java}
>     void bind(String id, Class<?> type, Object bean)
> {code}
> The underlying implementation is roughly:
> {code:java}
>     void bind(String id, Class<?> type, Object bean) {
>         computeIfAbsent(id, k -> new LinkedHashMap<>()).put(type, bean);
>     }
> {code}
> So assuming I have a class MyLogComponent which extends LogComponent and I do 
> the following binding:
> {code:java}
>     Component a = new LogComponent()
>     Component b = new MyLogComponent()
>     registry.bind("log", LogComponent.class, a )
>     registry.bind("log", MyLogComponent.class, b)
> {code}
> then lookupByNameAndType may return different values depending on the type 
> used for looking up the beans:
> {code:java}
>     registry.lookupByNameAndType("log", LogComponent.class)  ==> a
>     registry.lookupByNameAndType("log", MyLogComponent.class)   ==> b
>     registry.lookupByNameAndType("log", DefaultComponent.class)  ==> a or b 
> (depends on the order)
> {code}



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to