Laird Nelson
Laird Nelson

Reputation: 16238

Why is the return value of injectionTarget.getInjectionPoints() ignored by Weld?

(I've also asked this question on weld-dev.)

In a portable extension observing ProcessInjectionTarget, I have set a custom InjectionTarget using documented mechanisms.

My custom InjectionTarget forwards to the container-supplied one in all cases except one.

I have added an InjectionPoint to the Set of InjectionPoints reported by my custom InjectionTarget.

In my bean class, if there is no bean that can satisfy demand for my custom injection target (just an ordinary field without the customary @Inject annotation), I can see that Weld doesn't like it: it throws different exceptions based on the situation, all of which reduce to the fact that, as expected, there is no "supplier" for a value to "fill" this custom "slot". This is all as expected.

As soon as I introduce a bean that does, in fact, make a value suitable for this "slot", Weld is satisfied and does not complain…until I look up the supposedly injected field, and discover that its value is null.

So Weld has recognized my injection point in some places (i.e. at some point it has called, and processed the results of, getInjectionPoints on my custom InjectionTarget), but in others (namely at my custom InjectionPoint's inject time) it ignores it.

Digging deeper, I found that ResourceInjector (which for some reason is the subclass involved) does not respect the return value of injectionTarget.getInjectionPoints(): https://github.com/weld/core/blob/5.1.3.Final/impl/src/main/java/org/jboss/weld/injection/producer/ResourceInjector.java#L62-L74

Is there therefore any point to implementing InjectionTarget#getInjectionPoints() with anything other than Set.of()? Should the injection mechanism provided by the container respect the InjectionPoints reported by the InjectionTarget that is being injected (surely yes)?

Upvotes: 1

Views: 16

Answers (0)

Related Questions