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 2011/10/01 20:56:18 UTC
svn commit: r1178070 - in /openwebbeans/trunk/webbeans-impl/src:
main/java/org/apache/webbeans/corespi/scanner/
main/java/org/apache/webbeans/util/
test/java/org/apache/webbeans/newtests/definition/
test/java/org/apache/webbeans/newtests/definition/pro...
Author: struberg
Date: Sat Oct 1 18:56:18 2011
New Revision: 1178070
URL: http://svn.apache.org/viewvc?rev=1178070&view=rev
Log:
OWB-616 CDI-1.1 change CDI-159 dont check private final methods for proxybility
private final and any static methods are no problem for creating proxies.
Added:
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/definition/
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/definition/proxyable/
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/definition/proxyable/ProxyableBeanTypeTest.java
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/definition/proxyable/beans/
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/definition/proxyable/beans/BeanWithPrivateFinalMethod.java
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/definition/proxyable/beans/BeanWithPublicFinalMethod.java
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/scanner/AbstractMetaDataDiscovery.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/disposes/DisposerMethodBeanTest.java
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/scanner/AbstractMetaDataDiscovery.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/scanner/AbstractMetaDataDiscovery.java?rev=1178070&r1=1178069&r2=1178070&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/scanner/AbstractMetaDataDiscovery.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/scanner/AbstractMetaDataDiscovery.java Sat Oct 1 18:56:18 2011
@@ -99,7 +99,6 @@ public abstract class AbstractMetaDataDi
}
}
- @Override
public void release()
{
initAnnotationDB();
@@ -171,7 +170,6 @@ public abstract class AbstractMetaDataDi
return annotationDB;
}
- @Override
public Set<String> getAllAnnotations(String className)
{
return annotationDB.getAnnotationIndex().get(className);
@@ -194,7 +192,6 @@ public abstract class AbstractMetaDataDi
/* (non-Javadoc)
* @see org.apache.webbeans.corespi.ScannerService#getBeanClasses()
*/
- @Override
public Set<Class<?>> getBeanClasses()
{
crossReferenceBeans();
@@ -240,19 +237,16 @@ public abstract class AbstractMetaDataDi
/* (non-Javadoc)
* @see org.apache.webbeans.corespi.ScannerService#getBeanXmls()
*/
- @Override
public Set<URL> getBeanXmls()
{
return Collections.unmodifiableSet(webBeansXmlLocations);
}
- @Override
public BDABeansXmlScanner getBDABeansXmlScanner()
{
return bdaBeansXmlScanner;
}
- @Override
public boolean isBDABeansXmlScanningEnabled()
{
return isBDAScannerEnabled;
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=1178070&r1=1178069&r2=1178070&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 Sat Oct 1 18:56:18 2011
@@ -1827,20 +1827,23 @@ public final class WebBeansUtil
if(!violationMessage.containsViolation())
{
- Constructor<?> cons = getNoArgConstructor(beanClass);
-
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)
{
- if (ClassUtil.isFinal(m.getModifiers()) && !m.isSynthetic() && !m.isBridge())
+ 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!",
Added: 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=1178070&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/definition/proxyable/ProxyableBeanTypeTest.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/definition/proxyable/ProxyableBeanTypeTest.java Sat Oct 1 18:56:18 2011
@@ -0,0 +1,74 @@
+/*
+ * 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;
+
+
+import org.apache.webbeans.exception.WebBeansConfigurationException;
+import org.apache.webbeans.newtests.AbstractUnitTest;
+import org.apache.webbeans.newtests.definition.proxyable.beans.BeanWithPrivateFinalMethod;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.apache.webbeans.newtests.definition.proxyable.beans.BeanWithPublicFinalMethod;
+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.
+ * See CDI-spec 5.4.1. This got changed in CDI-1.1 to also allow
+ * static and private methods to be final.
+ */
+public class ProxyableBeanTypeTest extends AbstractUnitTest
+{
+ @Test
+ public void testBeanWithPrivateFinalMethods()
+ {
+ Collection<Class<?>> beanClasses = new ArrayList<Class<?>>();
+ beanClasses.add(BeanWithPrivateFinalMethod.class);
+
+ try
+ {
+ startContainer(beanClasses, null);
+
+ BeanWithPrivateFinalMethod testInstance = getInstance(BeanWithPrivateFinalMethod.class);
+ Assert.assertNotNull(testInstance);
+
+ Assert.assertEquals(42, testInstance.externalMethod());
+ Assert.assertEquals(4711, testInstance.staticMethod());
+ }
+ finally
+ {
+ shutDownContainer();
+ }
+
+ }
+
+ @Test(expected = WebBeansConfigurationException.class)
+ public void testBeanWithPublicFinalMethods()
+ {
+ Collection<String> beanXmls = new ArrayList<String>();
+
+ Collection<Class<?>> beanClasses = new ArrayList<Class<?>>();
+ beanClasses.add(BeanWithPublicFinalMethod.class);
+
+ startContainer(beanClasses, beanXmls);
+ }
+}
Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/definition/proxyable/beans/BeanWithPrivateFinalMethod.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/definition/proxyable/beans/BeanWithPrivateFinalMethod.java?rev=1178070&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/definition/proxyable/beans/BeanWithPrivateFinalMethod.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/definition/proxyable/beans/BeanWithPrivateFinalMethod.java Sat Oct 1 18:56:18 2011
@@ -0,0 +1,44 @@
+/*
+ * 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.RequestScoped;
+
+/**
+ * This bean has a private final method.
+ * It should be possible to create a proxy for it.
+ */
+@RequestScoped
+public class BeanWithPrivateFinalMethod
+{
+ private final int internalMethod()
+ {
+ return 42;
+ }
+
+ public static int staticMethod()
+ {
+ return 4711;
+ }
+
+ public int externalMethod()
+ {
+ return internalMethod();
+ }
+}
Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/definition/proxyable/beans/BeanWithPublicFinalMethod.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/definition/proxyable/beans/BeanWithPublicFinalMethod.java?rev=1178070&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/definition/proxyable/beans/BeanWithPublicFinalMethod.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/definition/proxyable/beans/BeanWithPublicFinalMethod.java Sat Oct 1 18:56:18 2011
@@ -0,0 +1,39 @@
+/*
+ * 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.RequestScoped;
+
+/**
+ * This bean has a public final method.
+ * It should NOT be possible to create a proxy for it!
+ */
+@RequestScoped
+public class BeanWithPublicFinalMethod
+{
+
+ /**
+ * public final methods must create an Exception because it cannot get proxied.
+ * @return
+ */
+ public final int externalMethod()
+ {
+ return 42;
+ }
+}
Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/disposes/DisposerMethodBeanTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/disposes/DisposerMethodBeanTest.java?rev=1178070&r1=1178069&r2=1178070&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/disposes/DisposerMethodBeanTest.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/disposes/DisposerMethodBeanTest.java Sat Oct 1 18:56:18 2011
@@ -50,7 +50,8 @@ public class DisposerMethodBeanTest exte
bean.destroy(model, cc);
Assert.assertTrue(DisposerMethodBean.OK);
-
+
+ shutDownContainer();
}
}