[cdi-dev] dependent bean handling

Mark Struberg struberg at yahoo.de
Wed Jun 4 12:13:03 EDT 2014


I came across this in org.jboss.cdi.tck.tests.implementation.producer.method.definition.ProducerMethodDefinitionTest ,but other methods might contain something similar:

    @SpecAssertions({ @SpecAssertion(section = DISPOSER_METHOD, id = "b") })
    public void testStaticDisposerMethod() throws Exception {
        assert getBeans(String.class, TAME_LITERAL).size() == 1;
        String aString = getContextualReference(String.class, TAME_LITERAL);
        Bean<String> stringBean = getBeans(String.class, TAME_LITERAL).iterator().next();
        CreationalContext<String> creationalContext = getCurrentManager().createCreationalContext(stringBean);
        stringBean.destroy(aString, creationalContext);
        assert BeanWithStaticProducerMethod.stringDestroyed;

the Dependent producer gets called via BeanManager#getReference _internally_ by using a 'throw away' CreationalContext
And then you later create a _new_ CreationalContext and use this for bean.destroy.

We should rather use the original CC. As is it now, this test is on the edge of being illegal ;)


More information about the cdi-dev mailing list