Martin,

Knowing that I don't have any reference to an injection point, what would you recommend I pass in as a dummy injection point?

John

On Fri, Aug 4, 2017 at 8:07 AM Martin Kouba <mkouba@redhat.com> wrote:
Hm, I think BeanManager.getReference() should not be used here, see also
6.5.3. Contextual reference for a bean [1]:

"The container must ensure that every injection point of type
InjectionPoint and qualifier @Default of any dependent object
instantiated during this process receives a null value if it is not
being injected into any injection point."

However, in Weld you could use
BeanManager.getInjectableReference(InjectionPoint, CreationalContext<?>)
and provide some dummy IP. See for example
https://github.com/weld/core/blob/master/tests-arquillian/src/test/java/org/jboss/weld/tests/injectionPoint/custom/BarBean.java#L50.

FYI there is a TCK test that verifies the InjectionPoint is null if
using getReference() outside custom bean's create:
org.jboss.cdi.tck.tests.lookup.injectionpoint.InjectionPointTest#testNullInjectionPointInjectedIntoNonInjectedObject()

Martin

[1]
http://docs.jboss.org/cdi/spec/1.2/cdi-spec.html#contextual_reference

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

--
Martin Kouba
Senior Software Engineer
Red Hat, Czech Republic