openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1577991 - in /openwebbeans/branches/owb_1.2.x: ./ webbeans-impl/src/main/java/org/apache/webbeans/config/ webbeans-impl/src/main/java/org/apache/webbeans/util/ webbeans-impl/src/test/java/org/apache/webbeans/newtests/definition/proxyable/
Date Sun, 16 Mar 2014 08:06:12 GMT
Author: struberg
Date: Sun Mar 16 08:06:11 2014
New Revision: 1577991

URL: http://svn.apache.org/r1577991
Log:
OWB-942 backport unproxyable bean check from trunk to owb-1.2.x


Modified:
    openwebbeans/branches/owb_1.2.x/   (props changed)
    openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/config/DeploymentValidationService.java
    openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java
    openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/util/InjectionExceptionUtil.java
    openwebbeans/branches/owb_1.2.x/webbeans-impl/src/test/java/org/apache/webbeans/newtests/definition/proxyable/ProxyableBeanTypeTest.java

Propchange: openwebbeans/branches/owb_1.2.x/
------------------------------------------------------------------------------
    svn:mergeinfo = /openwebbeans/trunk:1577953

Modified: openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/config/DeploymentValidationService.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/config/DeploymentValidationService.java?rev=1577991&r1=1577990&r2=1577991&view=diff
==============================================================================
--- openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/config/DeploymentValidationService.java
(original)
+++ openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/config/DeploymentValidationService.java
Sun Mar 16 08:06:11 2014
@@ -56,7 +56,7 @@ public class DeploymentValidationService
      */
     public void validateProxyable(OwbBean<?> bean)
     {
-        //Unproxiable test for NormalScoped beans
+        // Unproxyable test for NormalScoped beans
         if (webBeansContext.getBeanManagerImpl().isNormalScope(bean.getScope()))
         {
             ViolationMessageBuilder violationMessage = ViolationMessageBuilder.newViolation();
@@ -82,17 +82,13 @@ public class DeploymentValidationService
                         violationMessage.addLine(beanClass.getName(), " is a final class!
CDI doesn't allow to proxy that.");
                     }
 
-                    Method[] methods = SecurityUtil.doPrivilegedGetDeclaredMethods(beanClass);
-                    for (Method m : methods)
+                    String finalMethodName = hasNonPrivateFinalMethod(beanClass);
+                    if (finalMethodName != null)
                     {
-                        int modifiers = m.getModifiers();
-                        if (Modifier.isFinal(modifiers) && !Modifier.isPrivate(modifiers)
&&
-                            !m.isSynthetic() && !m.isBridge())
-                        {
-                            violationMessage.addLine(beanClass.getName(), " has final method
"+ m + " CDI doesn't allow to proxy that.");
-                        }
+                        violationMessage.addLine(beanClass.getName(), " has final method
"+ finalMethodName + " CDI doesn't allow to proxy that.");
                     }
 
+
                     Constructor<?> cons = webBeansContext.getWebBeansUtil().getNoArgConstructor(beanClass);
                     if (cons == null)
                     {
@@ -115,6 +111,38 @@ public class DeploymentValidationService
     }
 
     /**
+     * check if the given class has any non-private, non-static final method
+     * @return the method name or <code>null</code> if there is no such method.
+     */
+    private String hasNonPrivateFinalMethod(Class<?> beanClass)
+    {
+        if (beanClass == Object.class)
+        {
+            return null;
+        }
+
+        // we also need to check the methods of the parent classes
+        String finalMethodName = hasNonPrivateFinalMethod(beanClass.getSuperclass());
+        if (finalMethodName != null)
+        {
+            return finalMethodName;
+        }
+
+        Method[] methods = SecurityUtil.doPrivilegedGetDeclaredMethods(beanClass);
+        for (Method m : methods)
+        {
+            int modifiers = m.getModifiers();
+            if (Modifier.isFinal(modifiers) && !Modifier.isPrivate(modifiers) &&
!Modifier.isStatic(modifiers) &&
+                !m.isSynthetic() && !m.isBridge())
+            {
+                return m.getName();
+            }
+        }
+
+        return null;
+    }
+
+    /**
      * If bean is passivation capable, it validate all of its dependencies.
      * @throws org.apache.webbeans.exception.WebBeansConfigurationException if not satisfy
passivation dependencies
      */

Modified: openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java?rev=1577991&r1=1577990&r2=1577991&view=diff
==============================================================================
--- openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java
(original)
+++ openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java
Sun Mar 16 08:06:11 2014
@@ -247,8 +247,10 @@ public final class ClassUtil
      * package-private method will get skipped and treated similarly to private methods.
      *
      * Note: we filter out the {@link Object#finalize()} method as users must not deal with
it.
+     * @param topClass the class to start with. Then move up the hierarchy
+     * @param excludeFinalMethods whether final classes should get excluded from the result
      */
-    public static List<Method> getNonPrivateMethods(Class<?> topClass, boolean
noFinalMethods)
+    public static List<Method> getNonPrivateMethods(Class<?> topClass, boolean
excludeFinalMethods)
     {
         Map<String, List<Method>> methodMap = new HashMap<String, List<Method>>();
         List<Method> allMethods = new ArrayList<Method>(10);
@@ -271,7 +273,7 @@ public final class ClassUtil
                 {
                     continue;
                 }
-                if (noFinalMethods && Modifier.isFinal(modifiers))
+                if (excludeFinalMethods && Modifier.isFinal(modifiers))
                 {
                     continue;
                 }

Modified: openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/util/InjectionExceptionUtil.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/util/InjectionExceptionUtil.java?rev=1577991&r1=1577990&r2=1577991&view=diff
==============================================================================
--- openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/util/InjectionExceptionUtil.java
(original)
+++ openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/util/InjectionExceptionUtil.java
Sun Mar 16 08:06:11 2014
@@ -39,7 +39,7 @@ public class InjectionExceptionUtil
     public static void throwUnproxyableResolutionException(ViolationMessageBuilder violationMessage)
     {
         throw new UnproxyableResolutionException(
-                newViolation("WebBeans with api type with normal scope must be proxiable
to inject.")
+                newViolation("WebBeans with api type with normal scope must be proxyable.")
                         .addLine(violationMessage.toString())
                         .toString());
     }

Modified: openwebbeans/branches/owb_1.2.x/webbeans-impl/src/test/java/org/apache/webbeans/newtests/definition/proxyable/ProxyableBeanTypeTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/owb_1.2.x/webbeans-impl/src/test/java/org/apache/webbeans/newtests/definition/proxyable/ProxyableBeanTypeTest.java?rev=1577991&r1=1577990&r2=1577991&view=diff
==============================================================================
--- openwebbeans/branches/owb_1.2.x/webbeans-impl/src/test/java/org/apache/webbeans/newtests/definition/proxyable/ProxyableBeanTypeTest.java
(original)
+++ openwebbeans/branches/owb_1.2.x/webbeans-impl/src/test/java/org/apache/webbeans/newtests/definition/proxyable/ProxyableBeanTypeTest.java
Sun Mar 16 08:06:11 2014
@@ -21,20 +21,17 @@ package org.apache.webbeans.newtests.def
 
 import org.apache.webbeans.exception.WebBeansConfigurationException;
 import org.apache.webbeans.newtests.AbstractUnitTest;
-import org.apache.webbeans.newtests.definition.proxyable.beans.BeanWithPrivateFinalMethod;
+import org.apache.webbeans.newtests.definition.proxyable.beans.*;
 
 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;
 
 /**
  * This test checks for various conditions about NormalScope
- * Bean criterias regarding the ability to proxy those classes.
+ * Bean criteria regarding the ability to proxy those classes.
  * See CDI-spec 5.4.1. This got changed in CDI-1.1 to also allow
  * static and private methods to be final.
  */
@@ -66,12 +63,13 @@ public class ProxyableBeanTypeTest exten
     @Test(expected = WebBeansConfigurationException.class)
     public void testBeanWithPublicFinalMethods()
     {
-        Collection<String> beanXmls = new ArrayList<String>();
-
-        Collection<Class<?>> beanClasses = new ArrayList<Class<?>>();
-        beanClasses.add(BeanWithPublicFinalMethod.class);
+        startContainer(BeanWithPublicFinalMethod.class);
+    }
 
-        startContainer(beanClasses, beanXmls);
+    @Test(expected = WebBeansConfigurationException.class)
+    public void testSubclassBeanWithPublicFinalMethods()
+    {
+        startContainer(SubClassWithNormalScope.class, BaseClassWithPublicFinalMethod.class);
     }
 
     @Test



Mime
View raw message