Not possible to destroy normal scoped beans returned by producer method
by arjan tijms
Hi,
I have a simple producer:
@Produced
@SessionScoped
public void Foo getFoo() { return new Foo());
If I subsequently want to destroy the Bean using:
Set<Bean<?>> beans = beanManager.getBeans(Foo.class);
Bean<?> bean = (Bean<T>) beanManager.resolve(beans);
Context context = beanManager.getContext(bean.getScope());
((AlterableContext) context).destroy(bean);
Then in Weld 2.3.2 the destroy method of the super class
of org.jboss.weld.context.http.HttpSessionContextImpl is called:
org.jboss.weld.context.AbstractContext
Containing this code:
@Override
public void destroy(Contextual<?> contextual) {
if (!isActive()) {
throw new ContextNotActiveException();
}
checkContextInitialized();
if (contextual == null) {
throw ContextLogger.LOG.contextualIsNull();
}
final BeanStore beanStore = getBeanStore();
if (beanStore == null) {
throw ContextLogger.LOG.noBeanStoreAvailable(this);
}
BeanIdentifier id = getId(contextual);
ContextualInstance<?> beanInstance = beanStore.remove(id);
if (beanInstance != null) {
RequestScopedCache.invalidate();
destroyContextualInstance(beanInstance);
}
}
Now the getBeanStore() method
(from org.jboss.weld.context.AbstractBoundContext) returns an
org.jboss.weld.context.beanstore.http.LazySessionBeanStore and this bean
store does *not* contain the Foo bean (no key for its BeanIdentifier).
There are other session scoped beans there that have been instantiated for
the test, but Foo is missing.
If subsequently the session is destroyed, the same destroy method is called
on the org.jboss.weld.context.http.HttpSessionContextImpl eventually, but
now the getBeanStore() method returns
an org.jboss.weld.context.beanstore.http.EagerSessionBeanStore, and this
one *does* contain the Foo bean.
The other beans that the EagerSessionBeanStore contain are equal to the
ones in the LazySessionBeanStore, the only difference is the Foo bean.
Is this a bug in Weld or am I doing something wrong?
Kind regards,
Arjan Tijms
8 years, 2 months
Requesting comment on WELD-2062
by Benjamin Confino
Hello
A while back this issue was raised:
https://issues.jboss.org/browse/WELD-2062
I have recently encountered a similar issue in which an update to a
servlet does not take effect.
I have verified the solution proposed in WELD-2062 manually. By using my
eclipse debugger I was able to modify a variable and force
AnnotatedTypeIdentifier.equals() to return false, this resolved the issue.
My questions is, does AnnotatedTypeIdentifier.equals() need to be modified
to use the class instead of the className as suggested in WELD-2062 or is
this an integration issue where websphere has failed to provide the
required information?
Regards
Benjamin
Unless stated otherwise above:
IBM United Kingdom Limited - Registered in England and Wales with number
741598.
Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU
8 years, 3 months