I need to write a quick unit test to verify, but I think this may still be
missing non-public inherited methods.

Previously it only used getDeclaredMethods, which would return all all
private, protected, default and public methods for the class, but did not
contain any inherited methods.  If I'm reading this change correctly it now
adds getMethods which will add public inherited methods but still doesn't
include protected or default methods.

I wonder if we should walk up the class hierarchy and call
getDeclaredMethods at each step.  Might need to discard private methods
found in superclasses as I'm not sure we need to worry about those being
called on the proxy.

On Tue, Feb 10, 2015 at 9:57 AM, <[email protected]> wrote:

> Author: tandraschko
> Date: Tue Feb 10 14:57:07 2015
> New Revision: 1658730
>
> URL: http://svn.apache.org/r1658730
> Log:
> OWB-1036 NormalScoped ASM proxies broken in some cases for partial beans
>
> Added:
>
> openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/interceptors/factory/beans/PartialBeanClass.java
>
> openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/interceptors/factory/beans/PartialBeanClassSuperClass.java
>
> openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/interceptors/factory/beans/PartialBeanClassSuperInterface.java
> Modified:
>
> openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java
>
> openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/interceptors/factory/NormalScopeProxyFactoryTest.java
>
> 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=1658730&r1=1658729&r2=1658730&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
> Tue Feb 10 14:57:07 2015
> @@ -305,8 +305,22 @@ public final class ClassUtil
>                                               Map<String, List<Method>>
> methodMap, List<Method> allMethods,
>                                               Class<?> clazz)
>      {
> +        List<Method> temp = new
> ArrayList<Method>(Arrays.asList(clazz.getMethods()));
>          for (Method method : clazz.getDeclaredMethods())
>          {
> +            if (!temp.contains(method))
> +            {
> +                temp.add(method);
> +            }
> +        }
> +
> +        for (Method method : temp)
> +        {
> +                       if (allMethods.contains(method))
> +                       {
> +                               continue;
> +                       }
> +
>              if (method.isBridge())
>              {
>                  // we have no interest in generics bridge methods
>
> Modified:
> openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/interceptors/factory/NormalScopeProxyFactoryTest.java
> URL:
> http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/interceptors/factory/NormalScopeProxyFactoryTest.java?rev=1658730&r1=1658729&r2=1658730&view=diff
>
> ==============================================================================
> ---
> openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/interceptors/factory/NormalScopeProxyFactoryTest.java
> (original)
> +++
> openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/interceptors/factory/NormalScopeProxyFactoryTest.java
> Tue Feb 10 14:57:07 2015
> @@ -38,6 +38,7 @@ import java.lang.reflect.Type;
>  import java.net.URL;
>  import java.net.URLClassLoader;
>  import java.util.Set;
> +import
> org.apache.webbeans.test.interceptors.factory.beans.PartialBeanClass;
>
>  import static org.junit.Assert.assertNotNull;
>
> @@ -207,6 +208,40 @@ public class NormalScopeProxyFactoryTest
>
>      }
>
> +    @Test
> +    public void textPartialBeanProxyCreation() 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<PartialBeanClass> proxyClass =
> pf.createProxyClass(classLoader, PartialBeanClass.class);
> +        Assert.assertNotNull(proxyClass);
> +
> +        PartialBeanClass internalInstance = new PartialBeanClass()
> +        {
> +            @Override
> +            public String willFail2()
> +            {
> +                return "";
> +            }
> +
> +            @Override
> +            public String willFail()
> +            {
> +                return "";
> +            }
> +        };
> +
> +        TestContextualInstanceProvider provider = new
> TestContextualInstanceProvider(internalInstance);
> +
> +        PartialBeanClass proxy = pf.createProxyInstance(proxyClass,
> provider);
> +
> +        proxy.willFail();
> +        proxy.willFail2();
> +        proxy.willFail3();
> +    }
>
>      /**
>       * Test if protected and package scope methods are proxied as well.
>
> Added:
> openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/interceptors/factory/beans/PartialBeanClass.java
> URL:
> http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/interceptors/factory/beans/PartialBeanClass.java?rev=1658730&view=auto
>
> ==============================================================================
> ---
> openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/interceptors/factory/beans/PartialBeanClass.java
> (added)
> +++
> openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/interceptors/factory/beans/PartialBeanClass.java
> Tue Feb 10 14:57:07 2015
> @@ -0,0 +1,30 @@
> +/*
> + * 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;
> +
> +import javax.enterprise.context.ApplicationScoped;
> +
> +@ApplicationScoped
> +public abstract class PartialBeanClass extends PartialBeanClassSuperClass
> implements PartialBeanClassSuperInterface
> +{
> +    public String willFail3()
> +    {
> +        return "";
> +    }
> +}
>
> Added:
> openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/interceptors/factory/beans/PartialBeanClassSuperClass.java
> URL:
> http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/interceptors/factory/beans/PartialBeanClassSuperClass.java?rev=1658730&view=auto
>
> ==============================================================================
> ---
> openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/interceptors/factory/beans/PartialBeanClassSuperClass.java
> (added)
> +++
> openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/interceptors/factory/beans/PartialBeanClassSuperClass.java
> Tue Feb 10 14:57:07 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 abstract class PartialBeanClassSuperClass
> +{
> +    public abstract String willFail2();
> +}
>
> Added:
> openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/interceptors/factory/beans/PartialBeanClassSuperInterface.java
> URL:
> http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/interceptors/factory/beans/PartialBeanClassSuperInterface.java?rev=1658730&view=auto
>
> ==============================================================================
> ---
> openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/interceptors/factory/beans/PartialBeanClassSuperInterface.java
> (added)
> +++
> openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/interceptors/factory/beans/PartialBeanClassSuperInterface.java
> Tue Feb 10 14:57:07 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 PartialBeanClassSuperInterface
> +{
> +    public String willFail();
> +}
>
>
>

Reply via email to