weld + infinispan
matlach Mar 31, 2012 12:16 PMHello everyone,
I'm currently having issues with an invalid observer injection point (claimed by weld) in the Infinispan cdi module.
At this point, I'm trying to understand what is considerated as a valid or invalid injection point to eventually fill a JIRA report, either on Infinispan or Weld.
Right now I'm looking at org.jboss.weld.event.ObserverMethodImpl :
/** * Performs validation of the observer method for compliance with the * specifications. */ private void checkObserverMethod() { // Make sure exactly one and only one parameter is annotated with Observes List<?> eventObjects = this.observerMethod.getAnnotated().getWeldParameters(Observes.class); if (this.reception.equals(Reception.IF_EXISTS) && declaringBean.getScope().equals(Dependent.class)) { throw new DefinitionException(INVALID_SCOPED_CONDITIONAL_OBSERVER, this); } if (eventObjects.size() > 1) { throw new DefinitionException(MULTIPLE_EVENT_PARAMETERS, this); } // Check for parameters annotated with @Disposes List<?> disposeParams = this.observerMethod.getAnnotated().getWeldParameters(Disposes.class); if (disposeParams.size() > 0) { throw new DefinitionException(INVALID_DISPOSES_PARAMETER, this); } // Check annotations on the method to make sure this is not a producer // method, initializer method, or destructor method. if (this.observerMethod.getAnnotated().isAnnotationPresent(Produces.class)) { throw new DefinitionException(INVALID_PRODUCER, this); } if (this.observerMethod.getAnnotated().isAnnotationPresent(Inject.class)) { throw new DefinitionException(INVALID_INITIALIZER, this); } boolean containerLifecycleObserverMethod = Observers.isContainerLifecycleObserverMethod(this); for (WeldParameter<?, ?> parameter : getMethod().getAnnotated().getWeldParameters()) { if (parameter.isAnnotationPresent(Named.class) && parameter.getAnnotation(Named.class).value().equals("")) { throw new DefinitionException(NON_FIELD_INJECTION_POINT_CANNOT_USE_NAMED, getMethod()); } // if this is an observer method for container lifecycle event, it must not inject anything besides BeanManager if (containerLifecycleObserverMethod && !parameter.isAnnotationPresent(Observes.class) && !BeanManager.class.equals(parameter.getBaseType())) { throw new DefinitionException(INVALID_INJECTION_POINT, this); } } }
the issue is related to this validation
// if this is an observer method for container lifecycle event, it must not inject anything besides BeanManager if (containerLifecycleObserverMethod && !parameter.isAnnotationPresent(Observes.class) && !BeanManager.class.equals(parameter.getBaseType())) { throw new DefinitionException(INVALID_INJECTION_POINT, this); }
which make sense when looking at the infinispan org.infinispan.cdi.InfinispanExtension :
void registerCacheConfigurations(@Observes AfterDeploymentValidation event, CacheManagerEventBridge eventBridge, @Any Instance<EmbeddedCacheManager> cacheManagers, BeanManager beanManager) {
If commenting out the invalid injection point exception in weld implementation, method in infinispan api will behave normally.
So, is Infinispan cdi implementation wrong ? or it's the weld implementation that is too strict, or maybe not implemented correctly ?
Here is the original infinispan forum question which also contain a test case to reproduce the issue :