Author: struberg
Date: Fri Aug 24 09:25:08 2012
New Revision: 1376872

URL: http://svn.apache.org/viewvc?rev=1376872&view=rev
Log:
OWB-696 fix unproxyable bean checks

Added:
    
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/definition/proxyable/beans/DependentBeanWithoutDefaultCt.java
    
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/definition/proxyable/beans/NonAbstractSubClassBean.java
Modified:
    
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
    
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/definition/proxyable/ProxyableBeanTypeTest.java

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=1376872&r1=1376871&r2=1376872&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
 Fri Aug 24 09:25:08 2012
@@ -1772,62 +1772,65 @@ public final class WebBeansUtil
         //Unproxiable test for NormalScoped beans
         if (isScopeTypeNormal(scopeType))
         {
-            Set<Type> types = bean.getTypes();
-
             ViolationMessageBuilder violationMessage = 
ViolationMessageBuilder.newViolation();
 
-            for(Type type : types)
+            Class<?> beanClass;
+            if (bean instanceof OwbBean) 
+            {
+                beanClass = ((OwbBean)bean).getReturnType();
+            }
+            else 
             {
-                Class<?> beanClass = ClassUtil.getClass(type);
+                beanClass = bean.getBeanClass();
+            }
+            
+            if(!beanClass.isInterface() && beanClass != Object.class)
+            {
+                if(beanClass.isPrimitive())
+                {
+                    violationMessage.addLine("It isn't possible to proxy a 
primitive type (" + beanClass.getName(), ")");
+                }
 
-                if(!beanClass.isInterface() && beanClass != Object.class)
+                if(ClassUtil.isArray(beanClass))
                 {
-                    if(beanClass.isPrimitive())
-                    {
-                        violationMessage.addLine("It isn't possible to use a 
primitive type (" + beanClass.getName(), ")");
-                    }
+                    violationMessage.addLine("It isn't possible to proxy an 
array type (", beanClass.getName(), ")");
+                }
 
-                    if(ClassUtil.isArray(beanClass))
+                if(!violationMessage.containsViolation())
+                {
+                    if (ClassUtil.isFinal(beanClass.getModifiers()))
                     {
-                        violationMessage.addLine("It isn't possible to use an 
array type (", beanClass.getName(), ")");
+                        violationMessage.addLine(beanClass.getName(), " is a 
final class! CDI doesn't allow to proxy that.");
                     }
 
-                    if(!violationMessage.containsViolation())
+                    Method[] methods = 
SecurityUtil.doPrivilegedGetDeclaredMethods(beanClass);
+                    for (Method m : methods)
                     {
-                        if (ClassUtil.isFinal(beanClass.getModifiers()))
-                        {
-                            violationMessage.addLine(beanClass.getName(), " is 
a final class! CDI doesn't allow that.");
-                        }
-
-                        Method[] methods = 
SecurityUtil.doPrivilegedGetDeclaredMethods(beanClass);
-                        for (Method m : methods)
-                        {
-                            int modifiers = m.getModifiers();
-                            if (ClassUtil.isFinal(modifiers) && 
!Modifier.isPrivate(modifiers) &&
-                                !m.isSynthetic() && !m.isBridge())
-                            {
-                                violationMessage.addLine(beanClass.getName(), 
" has final method "+ m + " CDI doesn't allow that.");
-                            }
-                        }
-
-                        Constructor<?> cons = getNoArgConstructor(beanClass);
-                        if (cons == null)
-                        {
-                            violationMessage.addLine(beanClass.getName(), " 
has no explicit no-arg constructor!",
-                                    "A public or protected constructor without 
args is required!");
-                        }
-                        else if (Modifier.isPrivate(cons.getModifiers()))
+                        int modifiers = m.getModifiers();
+                        if (ClassUtil.isFinal(modifiers) && 
!Modifier.isPrivate(modifiers) &&
+                            !m.isSynthetic() && !m.isBridge())
                         {
-                            violationMessage.addLine(beanClass.getName(), " 
has a >private< no-arg constructor! CDI doesn't allow that.");
+                            violationMessage.addLine(beanClass.getName(), " 
has final method "+ m + " CDI doesn't allow to proxy that.");
                         }
                     }
 
-                    //Throw Exception
-                    if(violationMessage.containsViolation())
+                    Constructor<?> cons = getNoArgConstructor(beanClass);
+                    if (cons == null)
+                    {
+                        violationMessage.addLine(beanClass.getName(), " has no 
explicit no-arg constructor!",
+                                "A public or protected constructor without 
args is required!");
+                    }
+                    else if (Modifier.isPrivate(cons.getModifiers()))
                     {
-                        throwUnproxyableResolutionException(violationMessage);
+                        violationMessage.addLine(beanClass.getName(), " has a 
>private< no-arg constructor! CDI doesn't allow to proxy that.");
                     }
                 }
+
+                //Throw Exception
+                if(violationMessage.containsViolation())
+                {
+                    throwUnproxyableResolutionException(violationMessage);
+                }
             }
         }
     }

Modified: 
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/definition/proxyable/ProxyableBeanTypeTest.java
URL: 
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/definition/proxyable/ProxyableBeanTypeTest.java?rev=1376872&r1=1376871&r2=1376872&view=diff
==============================================================================
--- 
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/definition/proxyable/ProxyableBeanTypeTest.java
 (original)
+++ 
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/definition/proxyable/ProxyableBeanTypeTest.java
 Fri Aug 24 09:25:08 2012
@@ -27,6 +27,8 @@ import java.util.ArrayList;
 import java.util.Collection;
 
 import 
org.apache.webbeans.newtests.definition.proxyable.beans.BeanWithPublicFinalMethod;
+import 
org.apache.webbeans.newtests.definition.proxyable.beans.DependentBeanWithoutDefaultCt;
+import 
org.apache.webbeans.newtests.definition.proxyable.beans.NonAbstractSubClassBean;
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -71,4 +73,16 @@ public class ProxyableBeanTypeTest exten
 
         startContainer(beanClasses, beanXmls);
     }
+
+    @Test
+    public void testNotInjectedBeanWithoutDefaultCt()
+    {
+        Collection<String> beanXmls = new ArrayList<String>();
+
+        Collection<Class<?>> beanClasses = new ArrayList<Class<?>>();
+        beanClasses.add(DependentBeanWithoutDefaultCt.class);
+        beanClasses.add(NonAbstractSubClassBean.class);
+
+        startContainer(beanClasses, beanXmls);
+    }
 }

Added: 
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/definition/proxyable/beans/DependentBeanWithoutDefaultCt.java
URL: 
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/definition/proxyable/beans/DependentBeanWithoutDefaultCt.java?rev=1376872&view=auto
==============================================================================
--- 
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/definition/proxyable/beans/DependentBeanWithoutDefaultCt.java
 (added)
+++ 
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/definition/proxyable/beans/DependentBeanWithoutDefaultCt.java
 Fri Aug 24 09:25:08 2012
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.webbeans.newtests.definition.proxyable.beans;
+
+/**
+ * Dependent scoped beans without a default-ct are not a problem if they do 
not get injected.
+ */
+public abstract class DependentBeanWithoutDefaultCt
+{
+
+    protected DependentBeanWithoutDefaultCt(String someId)
+    {
+        // nothing to do in this test
+    }
+
+    public int getX() {
+        return 42;
+    }
+
+    public abstract int getY();
+}

Added: 
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/definition/proxyable/beans/NonAbstractSubClassBean.java
URL: 
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/definition/proxyable/beans/NonAbstractSubClassBean.java?rev=1376872&view=auto
==============================================================================
--- 
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/definition/proxyable/beans/NonAbstractSubClassBean.java
 (added)
+++ 
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/definition/proxyable/beans/NonAbstractSubClassBean.java
 Fri Aug 24 09:25:08 2012
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.webbeans.newtests.definition.proxyable.beans;
+
+import javax.enterprise.context.ApplicationScoped;
+
+/**
+ */
+@ApplicationScoped
+public class NonAbstractSubClassBean extends DependentBeanWithoutDefaultCt
+{
+    public NonAbstractSubClassBean() {
+        super("someId");
+    }
+
+    @Override
+    public int getY() {
+        return 43;
+    }
+}


Reply via email to