[ 
https://issues.apache.org/jira/browse/OWB-1126?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18073689#comment-18073689
 ] 

Thomas Andraschko commented on OWB-1126:
----------------------------------------

cant reproduce anymore, will close it.


{code:java}
public class ProgrammaticApplicationScopedLookupOw1126Test extends 
AbstractUnitTest
{

    @Test
    public void programmaticApplicationScopedBeanLookupOw1126()
    {
        addExtension(new Ow1126Extension());
        startContainer(singleton(Ow1126Client.class), emptyList());

        final Ow1126Client client = getInstance(Ow1126Client.class);
        final Bean<?> bean = 
getBeanManager().getExtension(Ow1126Extension.class).getBean();
        final Ow1126Type value2 = (Ow1126Type) getBeanManager().getReference(
            bean,
            Ow1126Type.class,
            getBeanManager().createCreationalContext(bean));

        assertEquals(client.value1.getCounter(), value2.getCounter());
    }

    @Dependent
    public static class Ow1126Client
    {
        @Inject
        private Ow1126Type value1;
    }

    public static class Ow1126Type
    {
        private final String counter;

        public Ow1126Type()
        {
            this.counter = null;
        }

        public Ow1126Type(String counter)
        {
            this.counter = counter;
        }

        public String getCounter()
        {
            return counter;
        }
    }

    public static class Ow1126Extension implements Extension
    {

        private final Bean<?> bean = new Ow1126ProgrammaticBean();

        public Bean<?> getBean()
        {
            return bean;
        }

        void addBean(@Observes AfterBeanDiscovery abd)
        {
            abd.addBean(bean);
        }
    }

    public static class Ow1126ProgrammaticBean implements Bean<Ow1126Type>
    {

        private final AtomicInteger counter = new AtomicInteger();

        @Override
        public Set<InjectionPoint> getInjectionPoints()
        {
            return Collections.emptySet();
        }

        @Override
        public Class<?> getBeanClass()
        {
            return Ow1126Type.class;
        }

        @Override
        public Ow1126Type create(CreationalContext<Ow1126Type> context)
        {
            return new Ow1126Type("test-" + counter.incrementAndGet());
        }

        @Override
        public void destroy(Ow1126Type instance, CreationalContext<Ow1126Type> 
context)
        {
        }

        @Override
        public Set<Type> getTypes()
        {
            return singleton(Ow1126Type.class);
        }

        @Override
        public Set<Annotation> getQualifiers()
        {
            return singleton(DefaultLiteral.INSTANCE);
        }

        @Override
        public Class<? extends Annotation> getScope()
        {
            return ApplicationScoped.class;
        }

        @Override
        public String getName()
        {
            return null;
        }

        @Override
        public Set<Class<? extends Annotation>> getStereotypes()
        {
            return Collections.emptySet();
        }

        @Override
        public boolean isAlternative()
        {
            return false;
        }
    }
}

{code}


> Lookup of non passivating scope programmatic bean leads to incorrect 
> contextual references
> ------------------------------------------------------------------------------------------
>
>                 Key: OWB-1126
>                 URL: https://issues.apache.org/jira/browse/OWB-1126
>             Project: OpenWebBeans
>          Issue Type: Bug
>          Components: Context and Scopes
>    Affects Versions: 1.6.3
>            Reporter: Antonin Stefanutti
>            Priority: Major
>         Attachments: OwbTest.java, OwbTestBean.java, OwbTestExtension.java, 
> OwbType.java
>
>
> When adding a programmatic bean in an extension whose scope is 
> {{ApplicationScoped}}, and that bean instance is used to retrieve a 
> contextual instance of that bean, the contextual reference is not the same as 
> the one retrieve either by looking up the bean prior to retrieving the 
> contextual reference or with an injection point that resolves to that bean.
> Attached is a minimal reproducible test case.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to