]
Stuart Douglas resolved WELD-907.
---------------------------------
Assignee: Stuart Douglas
Fix Version/s: 1.1.2.Final
Resolution: Rejected
bean.getBeanClass() does not always return the type of the bean.
Consider:
class A {
@Produces
public B get() {
return new B();
}
}
In this case beanManager.getBeans(B.class) will return the Bean for the producer method.
If you call bean.getBeanClass() on this bean it will return A as getBeanClass() returns
the class the producer is defined on.
To do this properly you need to call bean.getTypes() and extract the most specialized type
from the set.
bean-lookup issue in Context#get(Contextual, CreationalContext)
---------------------------------------------------------------
Key: WELD-907
URL:
https://issues.jboss.org/browse/WELD-907
Project: Weld
Issue Type: Bug
Components: Scopes & Contexts
Affects Versions: 1.1.1.Final
Reporter: Gerhard Petracek
Assignee: Stuart Douglas
Fix For: 1.1.2.Final
this is a very special case which used to work before weld v1.1.1
e.g.:
Set<Bean<?>> beans1 = beanManager.getBeans(MyBean.class);
Class beanClass = beans.iterator().next().getBeanClass();
Set<Annotation> qualifiers = beans.iterator().next().getQualifiers();
Set<Bean<?>> beans2 = beanManager.getBeans(beanClass, qualifiers.toArray(new
Annotation[qualifiers.size()]));
beans1 is the same as beans2
that works without problems.
if you use the same in
Context#get(Contextual, CreationalContext)
it doesn't work. i haven't looked at the details but it might be due to the
performance optimizations.
the following example isn't that useful (so please don't ask for the reason) -
it's just the minimal code to reproduce the issue.
public <T> T get(Contextual<T> component, CreationalContext<T>
creationalContext)
{
Class beanClass = ((Bean<T>)component).getBeanClass();
Set<Annotation> qualifiers = ((Bean<T>)component).getQualifiers();
Set<Bean<?>> beans = CdiUtils.getBeanManager().getBeans(beanClass,
qualifiers.toArray(new Annotation[qualifiers.size()]));
//beans is empty
}
it isn't specified that it should work but it used to work with weld and it also
works with owb.
since there is (imo) no reason why it shouldn't work, it would be great if it gets
fixed!
--
This message is automatically generated by JIRA.
For more information on JIRA, see: