<div dir="ltr"><div><div><div>Hi Martin,<br></div>Although the spec does not enforce that @Specialized must be used in conjunction with @Alternative , I would like to unify the understanding of what the spec behavior of @Specialized on an disabled bean is. <br><br></div>Thanks<br></div>Emily<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Nov 23, 2015 at 10:06 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 Emily,<br>
<br>
the problem is Specialization is not defined per bean archive but per application. A bean is either specialized or not. Note that specialization is not tied to alternatives.<br>
<br>
WRT your use-case: the specializing bean should be enabled globally or in each bean archive which is using the specialized bean.<br>
<br>
Martin<br>
<br>
Dne 23.11.2015 v 10:54 Emily Jiang napsal(a):<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">
Thank you Tom and Matej for your response!<br>
The alternative was enabled in the archive beans-xml-modified.jar, but<br>
it is not enabled in the archive beans-xml-modified2.jar. The issue is<br>
not with alternative but with Specialized.<br>
<br>
At the moment, Weld specialized is effective even if itself is not<br>
enabled, which is not desirable because it disables other bean but<br>
itself is not enabled. As a consequence, this causes deployment error.<br>
<br>
The CDI 1.2 section 4.3  spec says:<br>
When an enabled bean, as defined in Section 5.1.2, “Enabled and disabled<br>
beans”, specializes<br>
a second bean, we can be certain that the second bean is never<br>
instantiated or called by the<br>
container. Even if the second bean defines a producer or observer<br>
method, the method will never<br>
be called.<br>
<br>
It is true the above sentence comments about an enabled bean. It hits an<br>
disabled bean should not specialize a second bean. If you guys think it<br>
is unclear, can we update the spec to clarify this scenario?<br>
<br>
By the way, OWB and Weld behave differently (Weld thinks a disabled bean<br>
still specializes a second bean while OWB thinks a disabled bean does<br>
NOT specialize a second bean). This is something we can leave to<br>
implementation. We should spec it!<br>
<br>
On Mon, Nov 23, 2015 at 8:45 AM, Matej Novotny &lt;<a href="mailto:manovotn@redhat.com" target="_blank">manovotn@redhat.com</a><br></span><span class="">
&lt;mailto:<a href="mailto:manovotn@redhat.com" target="_blank">manovotn@redhat.com</a>&gt;&gt; wrote:<br>
<br>
    Hello Emily<br>
<br>
    I agree with Tom. In your case, specialized producer is enabled (via<br>
    beans.xml) although only per bean archive.<br>
<br>
<br>
    And about this:<br>
    &gt;&gt;From Weld&#39;s perspective, any bean annotated with @Specialized disables a second bean regardless whether itself is active or not.<br>
<br>
    It is true, however the spec doesn&#39;t define how does a @Specialized<br>
    bean behave when it is disabled (or at least I haven&#39;t found that bit).<br>
    So this leaves it up to implementation and I can&#39;t really see a<br>
    problem with it. Why would you create a @Specialized bean and<br>
    disable it afterwards (with no other @Specialized and/or<br>
    @Alternative active)?<br>
<br>
<br>
    Matej<br>
<br>
    ----- Original Message -----<br></span><span class="">
    From: &quot;Tomas Remes&quot; &lt;<a href="mailto:tremes@redhat.com" target="_blank">tremes@redhat.com</a> &lt;mailto:<a href="mailto:tremes@redhat.com" target="_blank">tremes@redhat.com</a>&gt;&gt;<br>
    To: &quot;Emily Jiang&quot; &lt;<a href="mailto:emijiang6@googlemail.com" target="_blank">emijiang6@googlemail.com</a><br></span><span class="">
    &lt;mailto:<a href="mailto:emijiang6@googlemail.com" target="_blank">emijiang6@googlemail.com</a>&gt;&gt;<br>
    Cc: &quot;cdi-dev&quot; &lt;<a href="mailto:cdi-dev@lists.jboss.org" target="_blank">cdi-dev@lists.jboss.org</a> &lt;mailto:<a href="mailto:cdi-dev@lists.jboss.org" target="_blank">cdi-dev@lists.jboss.org</a>&gt;&gt;<br>
    Sent: Monday, November 23, 2015 8:33:44 AM<br>
    Subject: Re: [cdi-dev] Clarification on 4.3 Specialization<br>
<br>
<br>
    Hi Emily,<br>
<br>
    I am not sure I follow. What is disabled?<br>
    AlternativeCounterProducerModified? I can see<br>
    AlternativeCounterProducerModified is enabled in beans.xml of the<br>
    given bean archive and it means it is selected alternative only per<br>
    the bean archive. So I can&#39;t see any problem (or maybe I don&#39;t fully<br>
    understand).<br>
<br>
    Tom<br>
<br>
    ----- Original Message -----<br>
    From: &quot;Emily Jiang&quot; &lt;<a href="mailto:emijiang6@googlemail.com" target="_blank">emijiang6@googlemail.com</a><br></span><span class="">
    &lt;mailto:<a href="mailto:emijiang6@googlemail.com" target="_blank">emijiang6@googlemail.com</a>&gt;&gt;<br>
    To: &quot;cdi-dev&quot; &lt;<a href="mailto:cdi-dev@lists.jboss.org" target="_blank">cdi-dev@lists.jboss.org</a> &lt;mailto:<a href="mailto:cdi-dev@lists.jboss.org" target="_blank">cdi-dev@lists.jboss.org</a>&gt;&gt;<br>
    Sent: Sunday, November 22, 2015 10:42:29 PM<br>
    Subject: Re: [cdi-dev] Clarification on 4.3 Specialization<br>
<br>
    any thoughts?<br>
<br>
    Should a bean with @Specialize disable a bean even if it is disabled<br>
    itself?<br>
<br>
    On Thu, Nov 19, 2015 at 10:09 AM, Emily Jiang &lt;<br></span><div><div class="h5">
    <a href="mailto:emijiang6@googlemail.com" target="_blank">emijiang6@googlemail.com</a> &lt;mailto:<a href="mailto:emijiang6@googlemail.com" target="_blank">emijiang6@googlemail.com</a>&gt; &gt; wrote:<br>
<br>
<br>
<br>
<br>
    I have an application containing two wars.<br>
<br>
    testDiffBDA.war<br>
    testDiffBDA.war/WEB-INF/classes/test/diff/web/FrontEndServlet.class<br>
<br>
    @Inject CounterProducerConsumerModified2 bean;<br>
<br>
<br>
    beans-xml-modified2.jar<br>
    containing one bean and an empty-ish beans.xml :<br>
    @Inject@CounterModifiedQualifier String modifiedProducer;<br>
<br>
    beans-xml-modified.jar.jar<br>
    CounterModifiedQualifier (the interface)<br>
    CounterProducerModified (the bean implementing that interface)<br>
    AlternativeCounterProducerModified (an alternative specialized bean)<br>
    beans.xml<br>
    &lt;alternatives&gt;<br>
    &lt;class&gt;com.ibm.jcdi.test.beansxml.AlternativeCounterProducerModified&lt;/class&gt;<br>
    &lt;/alternatives&gt;<br>
<br>
    My application failed deployment with the error on Weld but worked<br>
    on OpenWebBeans<br>
<br>
    [ERROR ] CWWKZ0004E: An exception occurred while starting the<br>
    application testDiffBDA. The exception message was:<br>
    com.ibm.ws.container.service.state.StateChangeException:<br>
    org.jboss.weld.exceptions.DeploymentException: WELD-001408:<br>
    Unsatisfied dependencies for type String with qualifiers<br>
    @CounterModifiedQualifier<br>
    at injection point [BackedAnnotatedField] @Inject<br>
    @CounterModifiedQualifier<br>
    com.ibm.jcdi.test.beansxml.CounterProducerConsumerModified2.modifiedProducer<br>
    at<br>
    com.ibm.jcdi.test.beansxml.CounterProducerConsumerModified2.modifiedProducer(CounterProducerConsumerModified2.java:0)<br>
    --<br>
<br>
<br>
    After further investigation and talking to Martin from Weld, the<br>
    error was caused due to the fact of<br>
    AlternativeCounterProducerModified disabling the<br>
    CounterProducerModified bean but itself is not enabled in the jar of<br>
    beans-xml-modified2.jar. Therefore, no producer is active to produce<br>
    a bean with the qualifier CounterModifiedQualifier.<br>
<br>
     &gt;From Weld&#39;s perspective, any bean annotated with @Specialized<br>
    disables a second bean regardless whether itself is active or not.<br>
<br>
    My understanding is that the specialized should only take effect if<br>
    itself is enabled. Otherwise, we run into the situation of where the<br>
    specialized bean is not enabled but it disabled another bean. To me,<br>
    it is wrong.<br>
<br>
<br>
    I also checked the spec:<br>
    @Alternative @Specializes<br>
    public class MockAsynchronousService extends AsynchronousService {<br>
    ...<br>
    }<br>
    When an enabled bean, as defined in Section 5.1.2, “Enabled and<br>
    disabled beans”, specializes<br>
    a second bean, we can be certain that the second bean is never<br>
    instantiated or called by the<br>
    container. Even if the second bean defines a producer or observer<br>
    method, the method will never<br>
    be called.<br>
<br>
    The spec says only an enabled bean can specialize a second bean. I<br>
    would like to know what other people think.<br>
<br>
<br>
    Thanks<br>
    Emily<br>
    =================<br>
    Emily Jiang<br></div></div>
    <a href="mailto:ejiang@apache.org" target="_blank">ejiang@apache.org</a> &lt;mailto:<a href="mailto:ejiang@apache.org" target="_blank">ejiang@apache.org</a>&gt;<span class=""><br>
<br>
<br>
<br>
    --<br>
    Thanks<br>
    Emily<br>
    =================<br>
    Emily Jiang<br></span>
    <a href="mailto:ejiang@apache.org" target="_blank">ejiang@apache.org</a> &lt;mailto:<a href="mailto:ejiang@apache.org" target="_blank">ejiang@apache.org</a>&gt;<br>
<br>
    _______________________________________________<br>
    cdi-dev mailing list<br>
    <a href="mailto:cdi-dev@lists.jboss.org" target="_blank">cdi-dev@lists.jboss.org</a> &lt;mailto:<a href="mailto:cdi-dev@lists.jboss.org" target="_blank">cdi-dev@lists.jboss.org</a>&gt;<span class=""><br>
    <a href="https://lists.jboss.org/mailman/listinfo/cdi-dev" rel="noreferrer" target="_blank">https://lists.jboss.org/mailman/listinfo/cdi-dev</a><br>
<br>
    Note that for all code provided on this list, the provider licenses<br>
    the code under the Apache License, Version 2<br>
    (<a href="http://www.apache.org/licenses/LICENSE-2.0.html" rel="noreferrer" target="_blank">http://www.apache.org/licenses/LICENSE-2.0.html</a>). For all other<br>
    ideas provided on this list, the provider waives all patent and<br>
    other intellectual property rights inherent in such information.<br>
<br>
    --<br>
    Tomas Remes<br>
<br>
<br>
    _______________________________________________<br>
    cdi-dev mailing list<br></span>
    <a href="mailto:cdi-dev@lists.jboss.org" target="_blank">cdi-dev@lists.jboss.org</a> &lt;mailto:<a href="mailto:cdi-dev@lists.jboss.org" target="_blank">cdi-dev@lists.jboss.org</a>&gt;<span class=""><br>
    <a href="https://lists.jboss.org/mailman/listinfo/cdi-dev" rel="noreferrer" target="_blank">https://lists.jboss.org/mailman/listinfo/cdi-dev</a><br>
<br>
    Note that for all code provided on this list, the provider licenses<br>
    the code under the Apache License, Version 2<br>
    (<a href="http://www.apache.org/licenses/LICENSE-2.0.html" rel="noreferrer" target="_blank">http://www.apache.org/licenses/LICENSE-2.0.html</a>). For all other<br>
    ideas provided on this list, the provider waives all patent and<br>
    other intellectual property rights inherent in such information.<br>
<br>
<br>
<br>
<br>
--<br>
Thanks<br>
Emily<br>
=================<br>
Emily Jiang<br>
</span><a href="mailto:ejiang@apache.org" target="_blank">ejiang@apache.org</a> &lt;mailto:<a href="mailto:ejiang@apache.org" target="_blank">ejiang@apache.org</a>&gt;<span class=""><br>
<br>
<br>
_______________________________________________<br>
cdi-dev mailing list<br>
<a href="mailto:cdi-dev@lists.jboss.org" target="_blank">cdi-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/cdi-dev" rel="noreferrer" target="_blank">https://lists.jboss.org/mailman/listinfo/cdi-dev</a><br>
<br>
Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (<a href="http://www.apache.org/licenses/LICENSE-2.0.html" rel="noreferrer" target="_blank">http://www.apache.org/licenses/LICENSE-2.0.html</a>). For all other ideas provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.<br>
<br>
</span></blockquote><span class="HOEnZb"><font color="#888888">
<br>
-- <br>
Martin Kouba<br>
Software Engineer<br>
Red Hat, Czech Republic<br>
</font></span></blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature">Thanks<br>Emily<br>=================<br>Emily Jiang<br><a href="mailto:ejiang@apache.org" target="_blank">ejiang@apache.org</a><br></div>
</div>