From c8daf608dc63895974804f5be5fe9b5bcf4dbba3 Mon Sep 17 00:00:00 2001 From: Jozef Hartinger Date: Fri, 27 Sep 2013 09:49:57 +0200 Subject: [PATCH] WFLY-2165 NPE starting WildFly with Spring 3 --- ...NonContextualComponentInjectionTarget.java | 6 ---- .../weld/injection/WeldComponentService.java | 28 +++++++++++++++++-- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/weld/src/main/java/org/jboss/as/weld/injection/NonContextualComponentInjectionTarget.java b/weld/src/main/java/org/jboss/as/weld/injection/NonContextualComponentInjectionTarget.java index 7c26bd3b9c57..40dc3a9bc123 100644 --- a/weld/src/main/java/org/jboss/as/weld/injection/NonContextualComponentInjectionTarget.java +++ b/weld/src/main/java/org/jboss/as/weld/injection/NonContextualComponentInjectionTarget.java @@ -23,7 +23,6 @@ import org.jboss.weld.injection.producer.LifecycleCallbackInvoker; import org.jboss.weld.injection.producer.NoopLifecycleCallbackInvoker; import org.jboss.weld.manager.BeanManagerImpl; -import org.jboss.weld.resources.ClassTransformer; /** * {@link javax.enterprise.inject.spi.InjectionTarget} implementation used for non-contextual EE components such as @@ -39,11 +38,6 @@ */ public class NonContextualComponentInjectionTarget extends BasicInjectionTarget { - @SuppressWarnings("unchecked") - public NonContextualComponentInjectionTarget(Class componentClass, Bean bean, BeanManagerImpl beanManager) { - this(beanManager.getServices().get(ClassTransformer.class).getEnhancedAnnotatedType((Class) componentClass, beanManager.getId()), bean, beanManager); - } - public NonContextualComponentInjectionTarget(EnhancedAnnotatedType type, Bean bean, BeanManagerImpl beanManager) { super(type, bean, beanManager); } diff --git a/weld/src/main/java/org/jboss/as/weld/injection/WeldComponentService.java b/weld/src/main/java/org/jboss/as/weld/injection/WeldComponentService.java index 316a7c535744..1878067fa711 100644 --- a/weld/src/main/java/org/jboss/as/weld/injection/WeldComponentService.java +++ b/weld/src/main/java/org/jboss/as/weld/injection/WeldComponentService.java @@ -30,6 +30,7 @@ import javax.enterprise.inject.spi.Bean; import javax.enterprise.inject.spi.InjectionTarget; +import javax.servlet.AsyncListener; import org.jboss.as.ee.component.ComponentDescription; import org.jboss.as.ejb3.component.messagedriven.MessageDrivenComponentDescription; @@ -42,12 +43,18 @@ import org.jboss.msc.service.StartException; import org.jboss.msc.service.StopContext; import org.jboss.msc.value.InjectedValue; +import org.jboss.weld.annotated.enhanced.EnhancedAnnotatedType; import org.jboss.weld.bean.ManagedBean; import org.jboss.weld.bean.SessionBean; import org.jboss.weld.ejb.spi.EjbDescriptor; +import org.jboss.weld.injection.producer.BasicInjectionTarget; import org.jboss.weld.injection.producer.InjectionTargetService; +import org.jboss.weld.injection.producer.NonProducibleInjectionTarget; import org.jboss.weld.literal.AnyLiteral; +import org.jboss.weld.logging.UtilLogger; import org.jboss.weld.manager.BeanManagerImpl; +import org.jboss.weld.resources.ClassTransformer; +import org.jboss.weld.util.Beans; import org.wildfly.security.manager.WildFlySecurityManager; /** @@ -101,7 +108,7 @@ public synchronized void start(final StartContext context) throws StartException beanManager = weldContainer.getValue().getBeanManager(beanDeploymentArchiveId); for (final Class interceptor : interceptorClasses) { - interceptorInjections.put(interceptor, new NonContextualComponentInjectionTarget(interceptor, null, beanManager)); + interceptorInjections.put(interceptor, createInjectionTarget(interceptor, null, beanManager)); } if (ejbName != null) { @@ -126,7 +133,7 @@ public synchronized void start(final StartContext context) throws StartException } } - NonContextualComponentInjectionTarget injectionTarget = new NonContextualComponentInjectionTarget(componentClass, bean, beanManager); + BasicInjectionTarget injectionTarget = createInjectionTarget(componentClass, bean, beanManager); if (componentDescription instanceof MessageDrivenComponentDescription || componentDescription instanceof WebComponentDescription) { // fire ProcessInjectionTarget for non-contextual components this.injectionTarget = beanManager.fireProcessInjectionTarget(injectionTarget.getAnnotated(), injectionTarget); @@ -140,6 +147,23 @@ public synchronized void start(final StartContext context) throws StartException } } + private BasicInjectionTarget createInjectionTarget(Class componentClass, Bean bean, BeanManagerImpl beanManager) { + EnhancedAnnotatedType type = beanManager.getServices().get(ClassTransformer.class).getEnhancedAnnotatedType((Class) componentClass, beanManager.getId()); + if (Beans.getBeanConstructor(type) == null) { + if (AsyncListener.class.isAssignableFrom(componentClass)) { + /* + * AsyncListeners may be CDI-incompatible as long as the application never calls + * javax.servletAsyncContext#createListener(Class) and only instantiates the listener + * itself. + */ + return new NonProducibleInjectionTarget<>(type, bean, beanManager); + } else { + throw UtilLogger.LOG.unableToFindConstructor(type); + } + } + return new NonContextualComponentInjectionTarget<>(type, bean, beanManager); + } + private ManagedBean findManagedBeanForWSComponent(Class definingClass) { Set> beans = beanManager.getBeans(definingClass, AnyLiteral.INSTANCE); for (Iterator> i = beans.iterator(); i.hasNext();) {