<div dir="ltr">Martin,<div><br></div><div>Knowing that I don'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 <<a href="mailto:mkouba@redhat.com">mkouba@redhat.com</a>> 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>
"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."<br>
<br>
However, in Weld you could use<br>
BeanManager.getInjectableReference(InjectionPoint, CreationalContext<?>)<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'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>
> Hi John,<br>
><br>
> Bean.getInjectionPoints() is only used during validation - returned<br>
> injection points are validated at initialization time, so for a custom<br>
> bean it makes sense to return an empty set as there are no real<br>
> injection points.<br>
><br>
> WRT lookup - what exactly do you try to accomplish? Do you try to obtain<br>
> InjectionPoint metadata from inside a custom dependent bean's create()<br>
> method? This should be possible although not clearly specified. I think<br>
> we have a test with BeanManager.getInjectableReference(InjectionPoint,<br>
> CreationalContext<?>) but I will need to double check.<br>
><br>
> I will also look at the geronimo-config repo.<br>
><br>
> Martin<br>
><br>
> Dne 4.8.2017 v 11:42 John D. Ament napsal(a):<br>
>> Hi<br>
>><br>
>> As the subject says. I have a library that registers a custom<br>
>> implementation of Bean, which has a method<br>
>><br>
>> @Override<br>
>> public Set<InjectionPoint> getInjectionPoints() {<br>
>> return Collections.emptySet();<br>
>> }<br>
>><br>
>> When testing this on Weld3, I have code that looks up the injection<br>
>> point, to find the annotations present. However, the following<br>
>> injection point lookup fails:<br>
>><br>
>> private static InjectionPoint findInjectionPoint(final<br>
>> BeanManager bm, final CreationalContext<?> ctx) {<br>
>> return InjectionPoint.class.cast(<br>
>> bm.getReference(bm.resolve(bm.getBeans(InjectionPoint.class)),<br>
>> InjectionPoint.class, ctx));<br>
>> }<br>
>><br>
>> so based on a CreationalContext I'm looking for InjectionPoint. Maybe<br>
>> there's a different way that this is supposed to work? If you're<br>
>> interested in giving it a shot, take a look at<br>
>> <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>
>> replicate the issue.<br>
>><br>
>> John<br>
>><br>
>><br>
>> _______________________________________________<br>
>> weld-dev mailing list<br>
>> <a href="mailto:weld-dev@lists.jboss.org" target="_blank">weld-dev@lists.jboss.org</a><br>
>> <a href="https://lists.jboss.org/mailman/listinfo/weld-dev" rel="noreferrer" target="_blank">https://lists.jboss.org/mailman/listinfo/weld-dev</a><br>
>><br>
><br>
<br>
--<br>
Martin Kouba<br>
Senior Software Engineer<br>
Red Hat, Czech Republic<br>
</blockquote></div></div></div>