IllegalArgumentException: WELD-001456 with @Observes(IF_EXISTS)
philipp91 Dec 11, 2013 1:54 PMHi,
I am using Weld 2.1.0.Final. Please read below for the error description. First I describe the overall situation (just in case anyone can give tips on that as well :-) ).
Currently I have the problem that I would technically need something like scope-specialization:
- I have a WindowContext and a @WindowScoped annotation that allows beans to live "per-window" in JavaFX.
- Thanks to previous help from this forum, it works fine.
- I have different types of windows. Each scope-instance will always be of one type only. But of course I use the same scope/Context for all kinds of windows that I have.
- In order to distinguish, I have an abstract class WindowInfo<T> and for each type of window I have a concrete class SomeKindOfWindowInfo extends WindowInfo<SomeClass>.
- Initially I ran into some problems using @Inject WindowInfo<?>, because there are of course mulitple beans available in my deployment that match this injection points (all the concrete WindowInfo-Implementations that I have). However, I managed to resolve that by either using the kind I want, or by calling BeanManager.getReference(bean, WindowInfo.class, null, true) manually. (Note that the "null" parameter is the CreationalContext, preventing new WindowInfo-instances from being created, and therefore only returns the single one I want).
- When I use @Observes, all instances are created anyway, so I used @Observes(notifyObserver=IF_EXISTS) instead, leading to the error described below.
=> If someone has a better idea on how to have different types of windows (each with its own model-type, and some specific code) allowing each window instance to have its own scope instance, that would be great. I read about Generic Beans from Weld extensions, but I didn't quite understand it, it's probably not what I want, because it doesn't have anything to do with the Java-generics I use?
Without regard to my current setup, there seems to be the following problem:
void receiveEvent(@Observes(notifyObserver=Reception.IF_EXISTS) SomeEventType event, SomeOtherClass parameter) { .. }
When firing this event (Event<SomeEventType> eventInstance.fire(new SomeEventType()), I get:
org.jboss.weld.exceptions.IllegalArgumentException: WELD-001456: Argument creationalContext must not be null
The reason is:
- ObserverMethodImpl.sendEvent() correctly finds out that there should be no CreationalContext.
- In case the bean does not exist, nothing happens.
- If the bean exists, the parameter will be resolved by MethodInjectionPoint.getParameterValues(), using the null-CreationalContext, leading to the exception in BeanManagerImpl.getReference(InjectionPoint, Bean, null).
In my case, the parameter type "SomeOtherClass" is the a sub-class of the class containing the receiveEvent-method, but the error might occur even without that.
Thank you for any help, workaround suggestions or even ideas about how to solve my window-typing-thing differently!
Philipp