openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tandrasc...@apache.org
Subject svn commit: r1659682 - in /openwebbeans/branches/owb_1.2.x/webbeans-impl/src: main/java/org/apache/webbeans/proxy/ test/java/org/apache/webbeans/newtests/interceptors/factory/ test/java/org/apache/webbeans/newtests/interceptors/factory/beans/
Date Fri, 13 Feb 2015 20:59:17 GMT
Author: tandraschko
Date: Fri Feb 13 20:59:17 2015
New Revision: 1659682

URL: http://svn.apache.org/r1659682
Log:
OWB-1036 NormalScoped ASM proxies broken in some cases for partial beans

Added:
    openwebbeans/branches/owb_1.2.x/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/factory/beans/PartialBeanInterface.java
    openwebbeans/branches/owb_1.2.x/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/factory/beans/PartialBeanSuperInterface2.java
    openwebbeans/branches/owb_1.2.x/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/factory/beans/PartialBeanSuperInterface3.java
Modified:
    openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/proxy/AbstractProxyFactory.java
    openwebbeans/branches/owb_1.2.x/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/factory/NormalScopeProxyFactoryTest.java

Modified: openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/proxy/AbstractProxyFactory.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/proxy/AbstractProxyFactory.java?rev=1659682&r1=1659681&r2=1659682&view=diff
==============================================================================
--- openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/proxy/AbstractProxyFactory.java
(original)
+++ openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/proxy/AbstractProxyFactory.java
Fri Feb 13 20:59:17 2015
@@ -24,6 +24,8 @@ import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
+import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.logging.Logger;
 
 import org.apache.webbeans.config.WebBeansContext;
@@ -189,14 +191,53 @@ public abstract class AbstractProxyFacto
     {
         String proxyClassFileName = proxyClassName.replace('.', '/');
 
-        final byte[] proxyBytes = generateProxy(classLoader, classToProxy, proxyClassName,
proxyClassFileName, interceptedMethods, nonInterceptedMethods);
-
+        final byte[] proxyBytes = generateProxy(classLoader,
+                classToProxy,
+                proxyClassName,
+                proxyClassFileName,
+                sortOutDuplicateMethods(interceptedMethods),
+                sortOutDuplicateMethods(nonInterceptedMethods));
+        
         Class<T> clazz = defineAndLoadClass(classLoader, proxyClassName, proxyBytes);
 
 
         return clazz;
     }
 
+    private Method[] sortOutDuplicateMethods(Method[] methods)
+    {
+        if (methods == null || methods.length == 0)
+        {
+            return null;
+        }
+
+        ArrayList<Method> duplicates = new ArrayList<Method>();
+
+        for (Method outer : methods)
+        {
+            for (Method inner : methods)
+            {
+                if (inner != outer
+                        && hasSameSignature(outer, inner)
+                        && !(duplicates.contains(outer) || duplicates.contains(inner)))
+                {
+                    duplicates.add(inner);
+                }
+            }
+        }
+
+        ArrayList<Method> outsorted = new ArrayList<Method>(Arrays.asList(methods));
+        outsorted.removeAll(duplicates);
+        return outsorted.toArray(new Method[outsorted.size()]);
+    }
+
+    private boolean hasSameSignature(Method a, Method b)
+    {
+        return a.getName().equals(b.getName())
+                && a.getReturnType().equals(b.getReturnType())
+                && Arrays.equals(a.getParameterTypes(), b.getParameterTypes());
+    }
+     
     private byte[] generateProxy(ClassLoader classLoader, Class<?> classToProxy, String
proxyClassName, String proxyClassFileName,
                                  Method[] interceptedMethods, Method[] nonInterceptedMethods)
             throws ProxyGenerationException

Modified: openwebbeans/branches/owb_1.2.x/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/factory/NormalScopeProxyFactoryTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/owb_1.2.x/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/factory/NormalScopeProxyFactoryTest.java?rev=1659682&r1=1659681&r2=1659682&view=diff
==============================================================================
--- openwebbeans/branches/owb_1.2.x/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/factory/NormalScopeProxyFactoryTest.java
(original)
+++ openwebbeans/branches/owb_1.2.x/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/factory/NormalScopeProxyFactoryTest.java
Fri Feb 13 20:59:17 2015
@@ -39,6 +39,7 @@ import java.net.URL;
 import java.net.URLClassLoader;
 import java.util.Set;
 import org.apache.webbeans.newtests.interceptors.factory.beans.PartialBeanClass;
+import org.apache.webbeans.test.interceptors.factory.beans.PartialBeanInterface;
 
 import static org.junit.Assert.assertNotNull;
 
@@ -243,6 +244,32 @@ public class NormalScopeProxyFactoryTest
         proxy.willFail3();
     }
 
+    @Test
+    public void testPartialBeanProxyCreation2() throws Exception
+    {
+        NormalScopeProxyFactory pf = new NormalScopeProxyFactory(new WebBeansContext());
+
+        // we take a fresh URLClassLoader to not blur the test classpath with synthetic classes.
+        ClassLoader classLoader = new URLClassLoader(new URL[0]);
+
+        Class<PartialBeanInterface> proxyClass = pf.createProxyClass(classLoader, PartialBeanInterface.class);
+        Assert.assertNotNull(proxyClass);
+
+        PartialBeanInterface internalInstance = new PartialBeanInterface()
+        {
+            @Override
+            public Object test(Object e) {
+                return e;
+            }
+        };
+
+        TestContextualInstanceProvider provider = new TestContextualInstanceProvider(internalInstance);
+
+        PartialBeanInterface proxy = pf.createProxyInstance(proxyClass, provider);
+
+        proxy.test(new Object());
+    }
+    
     /**
      * Test if protected and package scope methods are proxied as well.
      * @throws Exception

Added: openwebbeans/branches/owb_1.2.x/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/factory/beans/PartialBeanInterface.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/owb_1.2.x/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/factory/beans/PartialBeanInterface.java?rev=1659682&view=auto
==============================================================================
--- openwebbeans/branches/owb_1.2.x/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/factory/beans/PartialBeanInterface.java
(added)
+++ openwebbeans/branches/owb_1.2.x/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/factory/beans/PartialBeanInterface.java
Fri Feb 13 20:59:17 2015
@@ -0,0 +1,24 @@
+/*
+ * 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.interceptors.factory.beans;
+
+public interface PartialBeanInterface extends PartialBeanSuperInterface2<Object>, PartialBeanSuperInterface3<Object>
+{
+
+}
\ No newline at end of file

Added: openwebbeans/branches/owb_1.2.x/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/factory/beans/PartialBeanSuperInterface2.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/owb_1.2.x/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/factory/beans/PartialBeanSuperInterface2.java?rev=1659682&view=auto
==============================================================================
--- openwebbeans/branches/owb_1.2.x/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/factory/beans/PartialBeanSuperInterface2.java
(added)
+++ openwebbeans/branches/owb_1.2.x/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/factory/beans/PartialBeanSuperInterface2.java
Fri Feb 13 20:59:17 2015
@@ -0,0 +1,24 @@
+/*
+ * 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.interceptors.factory.beans;
+
+public interface PartialBeanSuperInterface2<E>
+{
+    E test(E e);
+}
\ No newline at end of file

Added: openwebbeans/branches/owb_1.2.x/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/factory/beans/PartialBeanSuperInterface3.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/owb_1.2.x/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/factory/beans/PartialBeanSuperInterface3.java?rev=1659682&view=auto
==============================================================================
--- openwebbeans/branches/owb_1.2.x/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/factory/beans/PartialBeanSuperInterface3.java
(added)
+++ openwebbeans/branches/owb_1.2.x/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/factory/beans/PartialBeanSuperInterface3.java
Fri Feb 13 20:59:17 2015
@@ -0,0 +1,24 @@
+/*
+ * 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.interceptors.factory.beans;
+
+public interface PartialBeanSuperInterface3<E>
+{
+    E test(E e);
+}
\ No newline at end of file



Mime
View raw message