openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1606890 - in /openwebbeans/trunk: webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ webbeans-impl/src/main/java/org/apache/webbeans/portable/ webbeans-impl/src/main/java/org/apache/webbeans/util/ webbeans-tck/
Date Mon, 30 Jun 2014 19:32:26 GMT
Author: rmannibucau
Date: Mon Jun 30 19:32:26 2014
New Revision: 1606890

URL: http://svn.apache.org/r1606890
Log:
validation for producers fields/methods

Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/FieldProducerFactory.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/ProducerFieldProducer.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/ProducerMethodProducer.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
    openwebbeans/trunk/webbeans-tck/testng-dev.xml

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/FieldProducerFactory.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/FieldProducerFactory.java?rev=1606890&r1=1606889&r2=1606890&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/FieldProducerFactory.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/FieldProducerFactory.java
Mon Jun 30 19:32:26 2014
@@ -23,9 +23,15 @@ import javax.enterprise.inject.spi.Bean;
 import javax.enterprise.inject.spi.Producer;
 
 import javax.enterprise.inject.spi.ProducerFactory;
+import javax.inject.Inject;
+
 import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.portable.ProducerFieldProducer;
 import org.apache.webbeans.util.Asserts;
+import org.apache.webbeans.util.ClassUtil;
+
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
 
 public class FieldProducerFactory<P> implements ProducerFactory<P>
 {
@@ -38,6 +44,24 @@ public class FieldProducerFactory<P> imp
     {
         Asserts.assertNotNull(producerField, "producer method may not be null");
         Asserts.assertNotNull(webBeansContext, "WebBeansContext may not be null");
+
+        if (producerField.isAnnotationPresent(Inject.class))
+        {
+            throw new IllegalArgumentException("producer field has @Inject annotation: "
+ producerField);
+        }
+
+        final Type type = producerField.getJavaMember().getGenericType();
+        if (ParameterizedType.class.isInstance(type))
+        {
+            for (final Type arg : ParameterizedType.class.cast(type).getActualTypeArguments())
+            {
+                if (ClassUtil.isWildCardType(arg))
+                {
+                    throw new IllegalArgumentException("Wildcard are forbidden: " + type);
+                }
+            }
+        }
+
         this.producerField = producerField;
         this.parent = parent;
         this.webBeansContext = webBeansContext;

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/ProducerFieldProducer.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/ProducerFieldProducer.java?rev=1606890&r1=1606889&r2=1606890&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/ProducerFieldProducer.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/ProducerFieldProducer.java
Mon Jun 30 19:32:26 2014
@@ -48,7 +48,10 @@ public class ProducerFieldProducer<T, P>
     public ProducerFieldProducer(Bean<P> owner, AnnotatedField<? super P> producerField,
WebBeansContext context)
     {
         super(Collections.<InjectionPoint>emptySet());
-        Asserts.assertNotNull(owner, "owner may not be null");
+        if (owner == null && !producerField.isStatic())
+        {
+            throw new IllegalArgumentException("owner may not be null");
+        }
         Asserts.assertNotNull(producerField, "field may not be null");
         Asserts.assertNotNull(context, "WebBeansContext may not be null");
         this.owner = owner;
@@ -98,7 +101,7 @@ public class ProducerFieldProducer<T, P>
         }
         finally
         {
-            if (owner.getScope().equals(Dependent.class))
+            if (owner != null && owner.getScope().equals(Dependent.class))
             {
                 owner.destroy(parentInstance, parentCreational);
             }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/ProducerMethodProducer.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/ProducerMethodProducer.java?rev=1606890&r1=1606889&r2=1606890&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/ProducerMethodProducer.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/ProducerMethodProducer.java
Mon Jun 30 19:32:26 2014
@@ -56,7 +56,10 @@ public class ProducerMethodProducer<T, P
                                   WebBeansContext webBeansContext)
     {
         super(points);
-        Asserts.assertNotNull(owner, "owner may not be null");
+        if (owner == null && !producerMethod.isStatic())
+        {
+            throw new IllegalArgumentException("owner may not be null");
+        }
         Asserts.assertNotNull(producerMethod, "method may not be null");
         Asserts.assertNotNull(webBeansContext, "WebBeansContext may not be null");
         if (!producerMethod.isStatic())

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java?rev=1606890&r1=1606889&r2=1606890&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
Mon Jun 30 19:32:26 2014
@@ -841,7 +841,7 @@ public final class WebBeansUtil
         }
         else
         {
-            throw new WebBeansConfigurationException("<Instance> field injection "
+ injectionPoint.toString()
+            throw new IllegalArgumentException("<Instance> field injection " + injectionPoint.toString()
                     + " must be defined as ParameterizedType with one actual type argument");
         }
 

Modified: openwebbeans/trunk/webbeans-tck/testng-dev.xml
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-tck/testng-dev.xml?rev=1606890&r1=1606889&r2=1606890&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-tck/testng-dev.xml (original)
+++ openwebbeans/trunk/webbeans-tck/testng-dev.xml Mon Jun 30 19:32:26 2014
@@ -19,7 +19,7 @@
   <test name="JSR-346 TCK">
     <classes>
       <class
-          name="org.jboss.cdi.tck.tests.extensions.beanManager.injectionPoint.CreateInjectionPointTest"
/>
+          name="org.jboss.cdi.tck.tests.extensions.beanManager.producer.SyntheticProducerTest"
/>
     </classes>
     <groups>
       <run>



Mime
View raw message