<div dir="ltr">Martin,<div><br></div><div>Knowing that I don&#39;t have any reference to an injection point, what would you recommend I pass in as a dummy injection point?</div><div><br></div><div>John<br><br><div class="gmail_quote"><div dir="ltr">On Fri, Aug 4, 2017 at 8:07 AM Martin Kouba &lt;<a href="mailto:mkouba@redhat.com">mkouba@redhat.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hm, I think BeanManager.getReference() should not be used here, see also<br>
6.5.3. Contextual reference for a bean [1]:<br>
<br>
&quot;The container must ensure that every injection point of type<br>
InjectionPoint and qualifier @Default of any dependent object<br>
instantiated during this process receives a null value if it is not<br>
being injected into any injection point.&quot;<br>
<br>
However, in Weld you could use<br>
BeanManager.getInjectableReference(InjectionPoint, CreationalContext&lt;?&gt;)<br>
and provide some dummy IP. See for example<br>
<a href="https://github.com/weld/core/blob/master/tests-arquillian/src/test/java/org/jboss/weld/tests/injectionPoint/custom/BarBean.java#L50" rel="noreferrer" target="_blank">https://github.com/weld/core/blob/master/tests-arquillian/src/test/java/org/jboss/weld/tests/injectionPoint/custom/BarBean.java#L50</a>.<br>
<br>
FYI there is a TCK test that verifies the InjectionPoint is null if<br>
using getReference() outside custom bean&#39;s create:<br>
org.jboss.cdi.tck.tests.lookup.injectionpoint.InjectionPointTest#testNullInjectionPointInjectedIntoNonInjectedObject()<br>
<br>
Martin<br>
<br>
[1]<br>
<a href="http://docs.jboss.org/cdi/spec/1.2/cdi-spec.html#contextual_reference" rel="noreferrer" target="_blank">http://docs.jboss.org/cdi/spec/1.2/cdi-spec.html#contextual_reference</a><br>
<br>
Dne 4.8.2017 v 13:05 Martin Kouba napsal(a):<br>
&gt; Hi John,<br>
&gt;<br>
&gt; Bean.getInjectionPoints() is only used during validation - returned<br>
&gt; injection points are validated at initialization time, so for a custom<br>
&gt; bean it makes sense to return an empty set as there are no real<br>
&gt; injection points.<br>
&gt;<br>
&gt; WRT lookup - what exactly do you try to accomplish? Do you try to obtain<br>
&gt; InjectionPoint metadata from inside a custom dependent bean&#39;s create()<br>
&gt; method? This should be possible although not clearly specified. I think<br>
&gt; we have a test with BeanManager.getInjectableReference(InjectionPoint,<br>
&gt; CreationalContext&lt;?&gt;) but I will need to double check.<br>
&gt;<br>
&gt; I will also look at the geronimo-config repo.<br>
&gt;<br>
&gt; Martin<br>
&gt;<br>
&gt; Dne 4.8.2017 v 11:42 John D. Ament napsal(a):<br>
&gt;&gt; Hi<br>
&gt;&gt;<br>
&gt;&gt; As the subject says.  I have a library that registers a custom<br>
&gt;&gt; implementation of Bean, which has a method<br>
&gt;&gt;<br>
&gt;&gt;      @Override<br>
&gt;&gt;      public Set&lt;InjectionPoint&gt; getInjectionPoints() {<br>
&gt;&gt;          return Collections.emptySet();<br>
&gt;&gt;      }<br>
&gt;&gt;<br>
&gt;&gt; When testing this on Weld3, I have code that looks up the injection<br>
&gt;&gt; point, to find the annotations present.  However, the following<br>
&gt;&gt; injection point lookup fails:<br>
&gt;&gt;<br>
&gt;&gt;      private static InjectionPoint findInjectionPoint(final<br>
&gt;&gt; BeanManager bm, final CreationalContext&lt;?&gt; ctx) {<br>
&gt;&gt;          return InjectionPoint.class.cast(<br>
&gt;&gt; bm.getReference(bm.resolve(bm.getBeans(InjectionPoint.class)),<br>
&gt;&gt; InjectionPoint.class, ctx));<br>
&gt;&gt;      }<br>
&gt;&gt;<br>
&gt;&gt; so based on a CreationalContext I&#39;m looking for InjectionPoint.  Maybe<br>
&gt;&gt; there&#39;s a different way that this is supposed to work?  If you&#39;re<br>
&gt;&gt; interested in giving it a shot, take a look at<br>
&gt;&gt; <a href="https://github.com/apache/geronimo-config" rel="noreferrer" target="_blank">https://github.com/apache/geronimo-config</a> and run the Weld3 profile to<br>
&gt;&gt; replicate the issue.<br>
&gt;&gt;<br>
&gt;&gt; John<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; _______________________________________________<br>
&gt;&gt; weld-dev mailing list<br>
&gt;&gt; <a href="mailto:weld-dev@lists.jboss.org" target="_blank">weld-dev@lists.jboss.org</a><br>
&gt;&gt; <a href="https://lists.jboss.org/mailman/listinfo/weld-dev" rel="noreferrer" target="_blank">https://lists.jboss.org/mailman/listinfo/weld-dev</a><br>
&gt;&gt;<br>
&gt;<br>
<br>
--<br>
Martin Kouba<br>
Senior Software Engineer<br>
Red Hat, Czech Republic<br>
</blockquote></div></div></div>