openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1521988 - in /openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/util/ test/java/org/apache/webbeans/newtests/ test/java/org/apache/webbeans/newtests/interceptors/factory/ test/java/org/apache/webbeans/newtests/interceptor...
Date Wed, 11 Sep 2013 19:05:50 GMT
Author: struberg
Date: Wed Sep 11 19:05:50 2013
New Revision: 1521988

URL: http://svn.apache.org/r1521988
Log:
OWB-898 correctly handle non-visible package-private methods from another package

Added:
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/factory/SubPackageInterceptedClass.java
      - copied, changed from r1521865, openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/factory/beans/ClassInterceptedClass.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/newtests/AbstractUnitTest.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/factory/NormalScopeProxyFactoryTest.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/factory/ProtectedUsageBean.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/factory/beans/ClassInterceptedClass.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/factory/beans/SomeBaseClass.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/resolution/InterceptorResolutionServiceTest.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/promethods/MethodProducer1Test.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/util/ClassUtilTest.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=1521988&r1=1521987&r2=1521988&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
Wed Sep 11 19:05:50 2013
@@ -241,13 +241,18 @@ public final class ClassUtil
      * The returned Map contains the methods divided by the methodName as key in the map
      * following all the methods with the same methodName in a List.
      *
+     * There is some special rule for package-private methods. Any non-visible
+     * 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
      */
-    public static List<Method> getNonPrivateMethods(Class<?> clazz, boolean noFinalMethods)
+    public static List<Method> getNonPrivateMethods(Class<?> rootClazz, boolean
noFinalMethods)
     {
         Map<String, List<Method>> methodMap = new HashMap<String, List<Method>>();
         List<Method> allMethods = new ArrayList<Method>(10);
 
+        Class<?> clazz = rootClazz;
+
         while (clazz != null)
         {
             for (Method method : clazz.getDeclaredMethods())
@@ -269,6 +274,18 @@ public final class ClassUtil
                     continue;
                 }
 
+                // check for package-private methods from a different package
+                if (!Modifier.isPublic(modifiers) && !Modifier.isProtected(modifiers))
+                {
+                    // private already got handled above, so we only had to check for not
public nor protected
+                    // we cannot see those methods if they are not in the same package as
the rootClazz
+                    if (!clazz.getPackage().getName().equals(rootClazz.getPackage().getName()))
+                    {
+                        continue;
+                    }
+
+                }
+
                 List<Method> methods = methodMap.get(method.getName());
                 if (methods == null)
                 {
@@ -825,7 +842,7 @@ public final class ClassUtil
 
     /**
      * Learn whether the specified class is defined with type parameters.
-     * @param clazz to check
+     * @param type to check
      * @return true if there are type parameters
      * @since 1.1.1
      */
@@ -996,7 +1013,7 @@ public final class ClassUtil
                 return false;
             }
             
-            if(!Modifier.isProtected(modifiers) && !Modifier.isPublic(modifiers))
                
+            if(!Modifier.isProtected(modifiers) && !Modifier.isPublic(modifiers))
             {
                 Class<?> superClass = superClassMethod.getDeclaringClass();
                 Class<?> subClass = subClassMethod.getDeclaringClass();

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/AbstractUnitTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/AbstractUnitTest.java?rev=1521988&r1=1521987&r2=1521988&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/AbstractUnitTest.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/AbstractUnitTest.java
Wed Sep 11 19:05:50 2013
@@ -179,7 +179,7 @@ public abstract class AbstractUnitTest
     @SuppressWarnings("unchecked")
     protected <T> Bean<T> getBean(Class<T> type, Annotation... qualifiers)
     {
-        Set<Bean<?>> beans = getBeanManager().getBeans(type, qualifiers);
+        Set beans = getBeanManager().getBeans(type, qualifiers);
         return (Bean<T>) getBeanManager().resolve(beans);
     }
 

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/factory/NormalScopeProxyFactoryTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/factory/NormalScopeProxyFactoryTest.java?rev=1521988&r1=1521987&r2=1521988&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/factory/NormalScopeProxyFactoryTest.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/factory/NormalScopeProxyFactoryTest.java
Wed Sep 11 19:05:50 2013
@@ -25,6 +25,8 @@ import java.net.URLClassLoader;
 import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.newtests.AbstractUnitTest;
 import org.apache.webbeans.newtests.interceptors.factory.beans.ClassInterceptedClass;
+import org.apache.webbeans.newtests.interceptors.factory.beans.SomeBaseClass;
+import org.apache.webbeans.newtests.interceptors.factory.SubPackageInterceptedClass;
 import org.apache.webbeans.proxy.NormalScopeProxyFactory;
 import org.junit.Assert;
 import org.junit.Test;
@@ -122,4 +124,17 @@ public class NormalScopeProxyFactoryTest
             return instance;
         }
     }
+
+    @Test
+    public void testContainerBoot() throws Exception
+    {
+        startContainer(ClassInterceptedClass.class, SomeBaseClass.class, SubPackageInterceptedClass.class);
+        ClassInterceptedClass instance = getInstance(ClassInterceptedClass.class);
+        Assert.assertNotNull(instance);
+        instance.getFloat();
+
+        SubPackageInterceptedClass subPackageInstance = getInstance(SubPackageInterceptedClass.class);
+        Assert.assertNotNull(subPackageInstance);
+        instance.getFloat();
+    }
 }

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/factory/ProtectedUsageBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/factory/ProtectedUsageBean.java?rev=1521988&r1=1521987&r2=1521988&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/factory/ProtectedUsageBean.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/factory/ProtectedUsageBean.java
Wed Sep 11 19:05:50 2013
@@ -47,5 +47,9 @@ public class ProtectedUsageBean
         return meaningOfLife;
     }
 
+    int packagePrivateMethod()
+    {
+        return 84;
+    }
 
 }

Copied: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/factory/SubPackageInterceptedClass.java
(from r1521865, openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/factory/beans/ClassInterceptedClass.java)
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/factory/SubPackageInterceptedClass.java?p2=openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/factory/SubPackageInterceptedClass.java&p1=openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/factory/beans/ClassInterceptedClass.java&r1=1521865&r2=1521988&rev=1521988&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/factory/beans/ClassInterceptedClass.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/factory/SubPackageInterceptedClass.java
Wed Sep 11 19:05:50 2013
@@ -16,18 +16,23 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.webbeans.newtests.interceptors.factory.beans;
+package org.apache.webbeans.newtests.interceptors.factory;
 
 import javax.annotation.PostConstruct;
 import javax.annotation.PreDestroy;
+import javax.enterprise.context.RequestScoped;
 
+import org.apache.webbeans.newtests.interceptors.factory.beans.SomeBaseClass;
 import org.apache.webbeans.test.component.intercept.webbeans.bindings.Transactional;
 
 /**
  * A simple class which is class-level intercepted
+ * but is in a different package than it's parent class.
+ * This is mainly for testing proxying of package-private methods.
  */
 @Transactional
-public class ClassInterceptedClass extends SomeBaseClass
+@RequestScoped
+public class SubPackageInterceptedClass extends SomeBaseClass
 {
     private boolean defaultCtInvoked = false;
 
@@ -35,7 +40,7 @@ public class ClassInterceptedClass exten
     private float f;
     private char c;
 
-    public ClassInterceptedClass()
+    public SubPackageInterceptedClass()
     {
         defaultCtInvoked = true;
     }
@@ -76,7 +81,7 @@ public class ClassInterceptedClass exten
         return f;
     }
 
-    public ClassInterceptedClass getSelf()
+    public SubPackageInterceptedClass getSelf()
     {
         return this;
     }
@@ -96,4 +101,9 @@ public class ClassInterceptedClass exten
         return 21;
     }
 
+    int packagePrivateMethod()
+    {
+        return 84;
+    }
+
 }

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/factory/beans/ClassInterceptedClass.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/factory/beans/ClassInterceptedClass.java?rev=1521988&r1=1521987&r2=1521988&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/factory/beans/ClassInterceptedClass.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/factory/beans/ClassInterceptedClass.java
Wed Sep 11 19:05:50 2013
@@ -20,6 +20,7 @@ package org.apache.webbeans.newtests.int
 
 import javax.annotation.PostConstruct;
 import javax.annotation.PreDestroy;
+import javax.enterprise.context.RequestScoped;
 
 import org.apache.webbeans.test.component.intercept.webbeans.bindings.Transactional;
 
@@ -27,6 +28,7 @@ import org.apache.webbeans.test.componen
  * A simple class which is class-level intercepted
  */
 @Transactional
+@RequestScoped
 public class ClassInterceptedClass extends SomeBaseClass
 {
     private boolean defaultCtInvoked = false;
@@ -96,4 +98,9 @@ public class ClassInterceptedClass exten
         return 21;
     }
 
+    int packagePrivateMethod()
+    {
+        return 84;
+    }
+
 }

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/factory/beans/SomeBaseClass.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/factory/beans/SomeBaseClass.java?rev=1521988&r1=1521987&r2=1521988&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/factory/beans/SomeBaseClass.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/factory/beans/SomeBaseClass.java
Wed Sep 11 19:05:50 2013
@@ -18,14 +18,23 @@
  */
 package org.apache.webbeans.newtests.interceptors.factory.beans;
 
+import javax.enterprise.context.RequestScoped;
+
 /**
- *
+ * Test class for our proxy bytecode generator logic.
  */
+@RequestScoped
 public class SomeBaseClass
 {
 
     protected String withAProtectedMethod()
     {
-        return "protedtMe";
+        return "protectMe";
     }
+
+    int packagePrivateMethod()
+    {
+        return 42;
+    }
+
 }

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/resolution/InterceptorResolutionServiceTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/resolution/InterceptorResolutionServiceTest.java?rev=1521988&r1=1521987&r2=1521988&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/resolution/InterceptorResolutionServiceTest.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/resolution/InterceptorResolutionServiceTest.java
Wed Sep 11 19:05:50 2013
@@ -89,7 +89,7 @@ public class InterceptorResolutionServic
 
         Map<Method, BusinessMethodInterceptorInfo> methodInterceptorInfos = interceptorInfo.getBusinessMethodsInfo();
         Assert.assertNotNull(methodInterceptorInfos);
-        Assert.assertEquals(10, methodInterceptorInfos.size());
+        Assert.assertEquals(11, methodInterceptorInfos.size());
 
         for (BusinessMethodInterceptorInfo mi : methodInterceptorInfos.values())
         {

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/promethods/MethodProducer1Test.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/promethods/MethodProducer1Test.java?rev=1521988&r1=1521987&r2=1521988&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/promethods/MethodProducer1Test.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/promethods/MethodProducer1Test.java
Wed Sep 11 19:05:50 2013
@@ -67,6 +67,11 @@ public class MethodProducer1Test extends
         Assert.assertNotNull(reference);
         
         Assert.assertTrue(reference instanceof InjectorofMethod1Bean);
+
+
+        ArrayList<String> value = ((InjectorofMethod1Bean) reference).getPt3();
+        Assert.assertNotNull(value);
+
         
         shutDownContainer();
     }

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/util/ClassUtilTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/util/ClassUtilTest.java?rev=1521988&r1=1521987&r2=1521988&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/util/ClassUtilTest.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/util/ClassUtilTest.java
Wed Sep 11 19:05:50 2013
@@ -38,6 +38,21 @@ public class ClassUtilTest {
     }
 
     @Test
+    public void testGetAllNonPrivateMethods_packagePrivate()
+    {
+        List<Method> nonPrivateMethods = ClassUtil.getNonPrivateMethods(MyOtherPackageSubClass.class,
false);
+
+        for (Method m : nonPrivateMethods)
+        {
+            if (MySuperClass.class.equals(m.getDeclaringClass()) &&
+                "packageMethod".equals(m.getName()))
+            {
+                Assert.fail("invisible package private method must not get listed");
+            }
+        }
+    }
+
+    @Test
     public void testIsOverridden() throws Exception
     {
         Assert.assertTrue(isOverridden(MySubClass.class, "publicMethod"));



Mime
View raw message