You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by st...@apache.org on 2014/03/16 00:27:58 UTC
svn commit: r1577953 - in /openwebbeans/trunk/webbeans-impl/src:
main/java/org/apache/webbeans/config/ main/java/org/apache/webbeans/util/
test/java/org/apache/webbeans/test/definition/proxyable/
test/java/org/apache/webbeans/test/definition/proxyable/...
Author: struberg
Date: Sat Mar 15 23:27:58 2014
New Revision: 1577953
URL: http://svn.apache.org/r1577953
Log:
OWB-941 handle final methods in superclasses.
txs to Ludovic Penet for catching this issue.
Added:
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/definition/proxyable/beans/BaseClassWithPublicFinalMethod.java
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/definition/proxyable/beans/SubClassWithNormalScope.java
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DeploymentValidationService.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/InjectionExceptionUtil.java
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/definition/proxyable/ProxyableBeanTypeTest.java
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DeploymentValidationService.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DeploymentValidationService.java?rev=1577953&r1=1577952&r2=1577953&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DeploymentValidationService.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DeploymentValidationService.java Sat Mar 15 23:27:58 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/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java?rev=1577953&r1=1577952&r2=1577953&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java Sat Mar 15 23:27:58 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/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/InjectionExceptionUtil.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/InjectionExceptionUtil.java?rev=1577953&r1=1577952&r2=1577953&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/InjectionExceptionUtil.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/InjectionExceptionUtil.java Sat Mar 15 23:27:58 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/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/definition/proxyable/ProxyableBeanTypeTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/definition/proxyable/ProxyableBeanTypeTest.java?rev=1577953&r1=1577952&r2=1577953&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/definition/proxyable/ProxyableBeanTypeTest.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/definition/proxyable/ProxyableBeanTypeTest.java Sat Mar 15 23:27:58 2014
@@ -21,6 +21,7 @@ package org.apache.webbeans.test.definit
import org.apache.webbeans.exception.WebBeansConfigurationException;
import org.apache.webbeans.test.AbstractUnitTest;
+import org.apache.webbeans.test.definition.proxyable.beans.BaseClassWithPublicFinalMethod;
import org.apache.webbeans.test.definition.proxyable.beans.BeanWithPrivateFinalMethod;
import java.util.ArrayList;
@@ -29,12 +30,13 @@ import java.util.Collection;
import org.apache.webbeans.test.definition.proxyable.beans.BeanWithPublicFinalMethod;
import org.apache.webbeans.test.definition.proxyable.beans.DependentBeanWithoutDefaultCt;
import org.apache.webbeans.test.definition.proxyable.beans.NonAbstractSubClassBean;
+import org.apache.webbeans.test.definition.proxyable.beans.SubClassWithNormalScope;
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 +68,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
Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/definition/proxyable/beans/BaseClassWithPublicFinalMethod.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/definition/proxyable/beans/BaseClassWithPublicFinalMethod.java?rev=1577953&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/definition/proxyable/beans/BaseClassWithPublicFinalMethod.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/definition/proxyable/beans/BaseClassWithPublicFinalMethod.java Sat Mar 15 23:27:58 2014
@@ -0,0 +1,34 @@
+/*
+ * 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.test.definition.proxyable.beans;
+
+/**
+ * This class has a public final method and is itself
+ * Dependent scoped. So it won't have any problems getting proxied
+ * itself. The problems arise if you subclass it in a class
+ * with a NormalScope.
+ */
+public class BaseClassWithPublicFinalMethod
+{
+
+ public final int getMeaningOfLife()
+ {
+ return 42;
+ }
+}
Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/definition/proxyable/beans/SubClassWithNormalScope.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/definition/proxyable/beans/SubClassWithNormalScope.java?rev=1577953&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/definition/proxyable/beans/SubClassWithNormalScope.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/definition/proxyable/beans/SubClassWithNormalScope.java Sat Mar 15 23:27:58 2014
@@ -0,0 +1,31 @@
+/*
+ * 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.test.definition.proxyable.beans;
+
+import javax.enterprise.context.ApplicationScoped;
+
+/**
+ * This class extends the base class which has a public final method.
+ * Thus this very class here cannot be proxied.
+ */
+@ApplicationScoped
+public class SubClassWithNormalScope extends BaseClassWithPublicFinalMethod
+{
+
+}