openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject [openwebbeans] branch master updated: OWB-1305 avoid the case an extension observes an event before its bean+instance can be looked up
Date Wed, 11 Dec 2019 10:14:19 GMT
This is an automated email from the ASF dual-hosted git repository.

rmannibucau pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/openwebbeans.git


The following commit(s) were added to refs/heads/master by this push:
     new 88ffcd7  OWB-1305 avoid the case an extension observes an event before its bean+instance
can be looked up
88ffcd7 is described below

commit 88ffcd7778faf7681b82db6e4c6998555cde17e5
Author: Romain Manni-Bucau <rmannibucau@gmail.com>
AuthorDate: Wed Dec 11 11:14:03 2019 +0100

    OWB-1305 avoid the case an extension observes an event before its bean+instance can be
looked up
---
 .../webbeans/portable/events/ExtensionLoader.java     | 19 +++++++++++++++----
 .../java/org/apache/webbeans/util/WebBeansUtil.java   | 19 -------------------
 2 files changed, 15 insertions(+), 23 deletions(-)

diff --git a/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/ExtensionLoader.java
b/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/ExtensionLoader.java
index b3b9913..d40ef20 100644
--- a/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/ExtensionLoader.java
+++ b/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/ExtensionLoader.java
@@ -32,16 +32,19 @@ import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.logging.Logger;
 
-import javax.enterprise.inject.spi.Bean;
 import javax.enterprise.inject.spi.DefinitionException;
 import javax.enterprise.inject.spi.DeploymentException;
 import javax.enterprise.inject.spi.Extension;
 
+import org.apache.webbeans.component.ExtensionBean;
+import org.apache.webbeans.component.creation.ExtensionBeanBuilder;
+import org.apache.webbeans.component.creation.ObserverMethodsBuilder;
 import org.apache.webbeans.config.OpenWebBeansConfiguration;
 import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.container.BeanManagerImpl;
 import org.apache.webbeans.exception.WebBeansException;
 import org.apache.webbeans.logger.WebBeansLoggerFacade;
+import org.apache.webbeans.util.Asserts;
 import org.apache.webbeans.util.ExceptionUtil;
 import org.apache.webbeans.util.WebBeansUtil;
 import org.apache.xbean.finder.archive.FileArchive;
@@ -201,13 +204,21 @@ public class ExtensionLoader
      * Add a CDI Extension to our internal list.
      * @param ext Extension to add
      */
-    public void addExtension(Extension ext)
+    public void addExtension(final Extension ext)
     {
-        Bean<?> bean = webBeansContext.getWebBeansUtil().createExtensionComponent(ext.getClass());
-        Class<?> extensionClass = ext.getClass();
+        final Class<Extension> extensionClass = (Class<Extension>) ext.getClass();
+        Asserts.nullCheckForClass(extensionClass);
         extensions.put(extensionClass, ext);
 
+        final ExtensionBeanBuilder<Extension> extensionBeanBuilder =
+                new ExtensionBeanBuilder<>(webBeansContext, extensionClass);
+        final ExtensionBean<Extension> bean = extensionBeanBuilder.getBean();
         manager.addBean(bean);
+
+        // since an extension can fire a ProcessInjectionPoint event when observing something
else than a lifecycle event
+        // and at the same time observe it, we must ensure to build the observers only once
the bean is available
+        new ObserverMethodsBuilder<>(webBeansContext, extensionBeanBuilder.getAnnotatedType())
+                .defineObserverMethods(bean);
     }
 
     /**
diff --git a/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java b/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
index 2842619..108622f 100644
--- a/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
+++ b/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
@@ -31,7 +31,6 @@ import org.apache.webbeans.component.DecoratorMetadataBean;
 import org.apache.webbeans.component.EnterpriseBeanMarker;
 import org.apache.webbeans.component.EventBean;
 import org.apache.webbeans.component.EventMetadataBean;
-import org.apache.webbeans.component.ExtensionBean;
 import org.apache.webbeans.component.InjectionPointBean;
 import org.apache.webbeans.component.InjectionTargetBean;
 import org.apache.webbeans.component.InstanceBean;
@@ -47,7 +46,6 @@ import org.apache.webbeans.component.ProducerMethodBean;
 import org.apache.webbeans.component.ResourceBean;
 import org.apache.webbeans.component.WebBeansType;
 import org.apache.webbeans.component.creation.BeanAttributesBuilder;
-import org.apache.webbeans.component.creation.ExtensionBeanBuilder;
 import org.apache.webbeans.component.creation.ManagedBeanBuilder;
 import org.apache.webbeans.component.creation.ObserverMethodsBuilder;
 import org.apache.webbeans.component.creation.ProducerFieldBeansBuilder;
@@ -479,23 +477,6 @@ public final class WebBeansUtil
     }
 
     /**
-     * Creates a new extension bean.
-     *
-     * @param <T> extension service class
-     * @param clazz impl. class
-     * @return a new extension service bean
-     */
-    public <T> ExtensionBean<T> createExtensionComponent(Class<T> clazz)
-    {
-        Asserts.nullCheckForClass(clazz);
-        ExtensionBeanBuilder<T> extensionBeanBuilder = new ExtensionBeanBuilder<>(webBeansContext,
clazz);
-        ExtensionBean<T> bean = extensionBeanBuilder.getBean();
-        new ObserverMethodsBuilder<>(webBeansContext, extensionBeanBuilder.getAnnotatedType()).defineObserverMethods(bean);
-        return bean;
-    }
-
-
-    /**
      * Creates a new manager bean instance.
      * @return new manager bean instance
      */


Mime
View raw message