You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by rm...@apache.org on 2014/12/22 19:16:04 UTC

svn commit: r1647364 - in /openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans: config/BeansDeployer.java util/SpecializationUtil.java

Author: rmannibucau
Date: Mon Dec 22 18:16:04 2014
New Revision: 1647364

URL: http://svn.apache.org/r1647364
Log:
ensuring parent of a @Spe class was not removed in ProcessBeanAttribute

Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/SpecializationUtil.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java?rev=1647364&r1=1647363&r2=1647364&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java Mon Dec 22 18:16:04 2014
@@ -235,9 +235,9 @@ public class BeansDeployer
 
                 SpecializationUtil specializationUtil = new SpecializationUtil(webBeansContext);
 
-                specializationUtil.removeDisabledTypes(annotatedTypes, true);
+                specializationUtil.removeDisabledTypes(annotatedTypes, null, true);
 
-                Map<AnnotatedType<?>, AnnotatedTypeData<?>> annotatedTypePreProcessing = getBeanAttributes(annotatedTypes);
+                final Map<AnnotatedType<?>, AnnotatedTypeData<?>> annotatedTypePreProcessing = getBeanAttributes(annotatedTypes);
                 annotatedTypes.clear(); // shouldn't be used anymore, view is now annotatedTypePreProcessing
 
                 //Deploy bean from XML. Also configures deployments, interceptors, decorators.
@@ -247,7 +247,18 @@ public class BeansDeployer
                 checkStereoTypes(scanner);
 
                 // Handle Specialization
-                specializationUtil.removeDisabledTypes(annotatedTypePreProcessing.keySet(), false);
+                specializationUtil.removeDisabledTypes(
+                        annotatedTypePreProcessing.keySet(),
+                        new SpecializationUtil.BeanAttributesProvider()
+                        {
+                            @Override
+                            public <T> BeanAttributes get(final AnnotatedType<T> at)
+                            {
+                                final AnnotatedTypeData<?> data = annotatedTypePreProcessing.get(at);
+                                return data == null ? null : data.beanAttributes;
+                            }
+                        },
+                        false);
 
                 // create beans from the discovered AnnotatedTypes
                 deployFromAnnotatedTypes(annotatedTypePreProcessing);

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/SpecializationUtil.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/SpecializationUtil.java?rev=1647364&r1=1647363&r2=1647364&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/SpecializationUtil.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/SpecializationUtil.java Mon Dec 22 18:16:04 2014
@@ -22,6 +22,7 @@ import javax.enterprise.inject.Alternati
 import javax.enterprise.inject.Specializes;
 import javax.enterprise.inject.Typed;
 import javax.enterprise.inject.spi.AnnotatedType;
+import javax.enterprise.inject.spi.BeanAttributes;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Type;
 import java.util.Arrays;
@@ -59,9 +60,12 @@ public class SpecializationUtil
     /**
      *
      * @param annotatedTypes all annotatypes
+     * @param attributeProvider if not null provides bean attributes to be able to validate types contains superclass
      * @param notSpecializationOnly first pass/2nd pass. First one removes only root beans, second one handles inheritance even in @Spe
      */
-    public void removeDisabledTypes(Collection<AnnotatedType<?>> annotatedTypes, boolean notSpecializationOnly)
+    public void removeDisabledTypes(Collection<AnnotatedType<?>> annotatedTypes,
+                                    BeanAttributesProvider attributeProvider,
+                                    boolean notSpecializationOnly)
     {
         if (annotatedTypes != null && !annotatedTypes.isEmpty())
         {
@@ -79,6 +83,15 @@ public class SpecializationUtil
                 {
                     Class<?> specialClass = annotatedType.getJavaClass();
                     Class<?> superClass = specialClass.getSuperclass();
+                    if (attributeProvider != null)
+                    {
+                        BeanAttributes<?> ba = attributeProvider.get(annotatedType);
+                        if (ba == null || !ba.getTypes().contains(superClass))
+                        {
+                            throw new WebBeansDeploymentException(new InconsistentSpecializationException("@Specializes class " + specialClass.getName()
+                                    + " does not extend a bean with a valid bean constructor - removed with ProcessBeanAttribute"));
+                        }
+                    }
 
                     if(superClass.equals(Object.class))
                     {
@@ -215,4 +228,9 @@ public class SpecializationUtil
         }
         return Collections.emptySet();
     }
+
+    public static interface BeanAttributesProvider
+    {
+        <T> BeanAttributes<T> get(AnnotatedType<T> at);
+    }
 }