<div dir="ltr">Hi,<div><br></div><div>Just a quick follow up, it seems that if the bean is touched in 1 request (so it&#39;s actually constructed and in the &quot;global&quot; bean store for the session), then destroyed in another request within the same session that hasn&#39;t touched the bean it fails.</div><div><br></div><div>But like you said, if the bean is touched within the same request (e.g. @Inject Foo foo; ... foo.toString();) then destroying it works.</div><div><br></div><div>I&#39;m not sure, do you think this is a bug, a spec issue, or &quot;just the way things are&quot;?</div><div><br></div><div>Kind regards,</div><div>Arjan Tijms</div><div><br></div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Sep 15, 2016 at 8:59 AM, arjan tijms <span dir="ltr">&lt;<a href="mailto:arjan.tijms@gmail.com" target="_blank">arjan.tijms@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi,<div><br></div><div>The produced Foo should have been used before it&#39;s destroyed, but I&#39;ll double check it&#39;s also used right before the destroy method is called in the same thread. I&#39;ll try to make a simple reproducer as well if it still doesn&#39;t work correctly then.</div><div><br></div><div>Kind regards,</div><div>Arjan Tijms</div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Sep 15, 2016 at 8:48 AM, Martin Kouba <span dir="ltr">&lt;<a href="mailto:mkouba@redhat.com" target="_blank">mkouba@redhat.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Arjan,<br>
<br>
a simple reproducer would be helpful. There are few edge cases around session context and HTTP session which are problematic (e.g. HttpSession.invalidate()).<br>
<br>
Do you call some method on the produced Foo before you call destroy? Because in Weld, normal scoped instances are created lazily and so does the HTTP session in case of @SessionScoped.<br>
<br>
Thanks,<br>
<br>
Martin<br>
<br>
Dne 14.9.2016 v 19:14 arjan tijms napsal(a):<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div>
Hi,<br>
<br>
I have a simple producer:<br>
<br>
@Produced<br>
@SessionScoped<br>
public void Foo getFoo() { return new Foo());<br>
<br>
If I subsequently want to destroy the Bean using:<br>
<br>
Set&lt;Bean&lt;?&gt;&gt; beans = beanManager.getBeans(Foo.class<wbr>);<br>
<br>
Bean&lt;?&gt; bean = (Bean&lt;T&gt;) beanManager.resolve(beans);<br>
Context context = beanManager.getContext(<a href="http://bean.ge" target="_blank">bean.ge</a><wbr>tScope());<br>
<br>
((AlterableContext) context).destroy(bean);<br>
<br>
Then in Weld 2.3.2 the destroy method of the super class<br>
of <a href="http://org.jboss.weld.context.http.Ht" target="_blank">org.jboss.weld.context.http.Ht</a><wbr>tpSessionContextImpl is called:<br>
<br>
org.jboss.weld.context.Abstrac<wbr>tContext<br>
<br>
Containing this code:<br>
<br>
    @Override<br>
    public void destroy(Contextual&lt;?&gt; contextual) {<br>
        if (!isActive()) {<br>
            throw new ContextNotActiveException();<br>
        }<br>
        checkContextInitialized();<br>
        if (contextual == null) {<br>
            throw ContextLogger.LOG.contextualIs<wbr>Null();<br>
        }<br>
        final BeanStore beanStore = getBeanStore();<br>
        if (beanStore == null) {<br>
            throw ContextLogger.LOG.noBeanStoreA<wbr>vailable(this);<br>
        }<br>
        BeanIdentifier id = getId(contextual);<br>
        ContextualInstance&lt;?&gt; beanInstance = beanStore.remove(id);<br>
        if (beanInstance != null) {<br>
            RequestScopedCache.invalidate(<wbr>);<br>
            destroyContextualInstance(bean<wbr>Instance);<br>
        }<br>
    }<br>
<br>
Now the getBeanStore() method<br>
(from org.jboss.weld.context.Abstrac<wbr>tBoundContext) returns an<br>
org.jboss.weld.context.beansto<wbr>re.http.LazySessionBeanStore and this bean<br>
store does *not* contain the Foo bean (no key for its BeanIdentifier).<br>
There are other session scoped beans there that have been instantiated<br>
for the test, but Foo is missing.<br>
<br>
If subsequently the session is destroyed, the same destroy method is<br>
called on the<br>
<a href="http://org.jboss.weld.context.http.Ht" target="_blank">org.jboss.weld.context.http.Ht</a><wbr>tpSessionContextImpl eventually, but now<br>
the getBeanStore() method returns<br>
an org.jboss.weld.context.beansto<wbr>re.http.EagerSessionBeanStore, and this<br>
one *does* contain the Foo bean.<br>
<br>
The other beans that the EagerSessionBeanStore contain are equal to the<br>
ones in the LazySessionBeanStore, the only difference is the Foo bean.<br>
<br>
Is this a bug in Weld or am I doing something wrong?<br>
<br>
Kind regards,<br>
Arjan Tijms<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br></div></div>
______________________________<wbr>_________________<br>
weld-dev mailing list<br>
<a href="mailto:weld-dev@lists.jboss.org" target="_blank">weld-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/weld-dev" rel="noreferrer" target="_blank">https://lists.jboss.org/mailma<wbr>n/listinfo/weld-dev</a><br>
<br>
</blockquote>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div>