[weld-issues] [JBoss JIRA] (WELD-911) Shared dependent instance injection with circular reference through decorator

Ales Justin (JIRA) jira-events at lists.jboss.org
Thu Mar 8 19:23:37 EST 2012


     [ https://issues.jboss.org/browse/WELD-911?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Ales Justin updated WELD-911:
-----------------------------

    Fix Version/s: 1.2.0.Beta1

    
> Shared dependent instance injection with circular reference through decorator
> -----------------------------------------------------------------------------
>
>                 Key: WELD-911
>                 URL: https://issues.jboss.org/browse/WELD-911
>             Project: Weld
>          Issue Type: Bug
>          Components: Scopes & Contexts
>    Affects Versions: 1.1.1.Final
>            Reporter: Christian Bauer
>            Assignee: Ales Justin
>             Fix For: 1.2.0.Beta1
>
>
> CDI spec section 6.4 says about @Dependent that "No injected instance of the bean is ever shared between multiple injection points."
> The following test shows that the same instance of @Dependent Foo is shared between multiple injection points, one in TestDecoratorInjection, the other in BarDecorator.
> {code}
> import org.jboss.weld.environment.se.Weld;
> import org.jboss.weld.environment.se.WeldContainer;
> import javax.annotation.PostConstruct;
> import javax.decorator.Decorator;
> import javax.decorator.Delegate;
> import javax.enterprise.inject.Any;
> import javax.inject.Inject;
> import javax.inject.Singleton;
> @Singleton
> public class TestDecoratorInjection {
>    public static final Weld weld = new Weld();
>    public static final WeldContainer weldContainer = weld.initialize();
>    public static void main(final String[] args) throws Exception {
>        weldContainer.instance().select(TestDecoratorInjection.class).get().test();
>    }
>    @Inject
>    Foo foo; // Dependent instance of TestDecoratorInjection
>    void test() {
>        foo.test();
>    }
>    public static class Foo {
>        @PostConstruct
>        void init() {
>            System.out.println("INIT FOO");
>        }
>        @Inject
>        Bar bar; // Dependent instance of Foo
>        void print() {
>            System.out.println("FOO");
>        }
>        void test() {
>            bar.print();
>        }
>    }
>    public static interface Bar {
>        void print();
>    }
>    public static class BarImpl implements Bar {
>        @Override
>        public void print() {
>            System.out.println("Bar");
>        }
>    }
>    @Decorator
>    public static abstract class BarDecorator implements Bar {
>        @Inject
>        @Delegate
>        @Any
>        Bar delegate;
>        @Inject
>        Foo foo; // Dependent instance of what?!
>        @Override
>        public void print() {
>            foo.print();
>        }
>    }
> }
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.jboss.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the weld-issues mailing list