openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1434655 - in /openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/proxy/ test/java/org/apache/webbeans/newtests/ test/java/org/apache/webbeans/test/unittests/disposal/
Date Thu, 17 Jan 2013 13:04:31 GMT
Author: struberg
Date: Thu Jan 17 13:04:30 2013
New Revision: 1434655

URL: http://svn.apache.org/viewvc?rev=1434655&view=rev
Log:
OWB-344 some packages are reserved

We must not create proxy classes with package names
java.*, javax.*, etc

Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/AbstractProxyFactory.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/AbstractUnitTest.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/disposal/DisposalTest.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/AbstractProxyFactory.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/AbstractProxyFactory.java?rev=1434655&r1=1434654&r2=1434655&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/AbstractProxyFactory.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/AbstractProxyFactory.java
Thu Jan 17 13:04:30 2013
@@ -94,6 +94,12 @@ public abstract class AbstractProxyFacto
     protected String getUnusedProxyClassName(ClassLoader classLoader, String proxyClassName)
     {
         String finalName = proxyClassName;
+
+        proxyClassName = fixPreservedPackage(proxyClassName, "java.");
+        proxyClassName = fixPreservedPackage(proxyClassName, "javax.");
+        proxyClassName = fixPreservedPackage(proxyClassName, "com.sun.");
+        proxyClassName = fixPreservedPackage(proxyClassName, "sun.misc.");
+
         for (int i = 0; i < MAX_CLASSLOAD_TRIES; i++)
         {
             try
@@ -112,6 +118,23 @@ public abstract class AbstractProxyFacto
         throw new WebBeansException("Unable to detect a free proxy class name based on: "
+ proxyClassName);
     }
 
+    /**
+     * Detect if the provided className is in the forbidden package.
+     * If so, move it to org.apache.webbeans.custom.
+     * @param forbiddenPackagePrefix including the '.', e.g. 'javax.'
+     */
+    private String fixPreservedPackage(final String className, final String forbiddenPackagePrefix)
+    {
+        String fixedClassName = className;
+
+        if (className.startsWith(forbiddenPackagePrefix))
+        {
+            fixedClassName = "org.apache.webbeans.custom." + className.substring(forbiddenPackagePrefix.length());
+        }
+
+        return fixedClassName;
+    }
+
 
     /**
      * @param classLoader to use for creating the class in

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=1434655&r1=1434654&r2=1434655&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
Thu Jan 17 13:04:30 2013
@@ -20,6 +20,7 @@ package org.apache.webbeans.newtests;
 
 import java.lang.annotation.Annotation;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.List;
 import java.util.Set;
@@ -48,7 +49,12 @@ public abstract class AbstractUnitTest
     {
 
     }
-    
+
+    protected void startContainer(Class<?>... beanClasses)
+    {
+        startContainer(Arrays.asList(beanClasses), null);
+    }
+
     protected void startContainer(Collection<Class<?>> beanClasses)
     {
         startContainer(beanClasses, null);

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/disposal/DisposalTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/disposal/DisposalTest.java?rev=1434655&r1=1434654&r2=1434655&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/disposal/DisposalTest.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/disposal/DisposalTest.java
Thu Jan 17 13:04:30 2013
@@ -18,46 +18,27 @@
  */
 package org.apache.webbeans.test.unittests.disposal;
 
+import javax.enterprise.context.RequestScoped;
 import java.util.List;
 
-import org.apache.webbeans.config.WebBeansContext;
-import org.apache.webbeans.context.ContextFactory;
-import org.apache.webbeans.test.TestContext;
+import org.apache.webbeans.newtests.AbstractUnitTest;
 import org.apache.webbeans.test.component.disposal.Disposal1;
 import org.junit.Assert;
-import org.junit.Before;
 import org.junit.Test;
 
-public class DisposalTest extends TestContext
+public class DisposalTest extends AbstractUnitTest
 {
 
-    public DisposalTest()
-    {
-        super(DisposalTest.class.getName());
-    }
-
-    @Before
-    public void init()
-    {
-        super.init();
-    }
-
     @Test
     public void testDisposal1()
     {
-        clear();
-
-        ContextFactory contextFactory = WebBeansContext.getInstance().getContextFactory();
-        contextFactory.initRequestContext(null);
-        contextFactory.initSessionContext(null);
-
-        defineManagedBean(Disposal1.class);
+        startContainer(Disposal1.class);
 
         @SuppressWarnings("unchecked")
-        List<Integer> list = (List<Integer>) getInstanceByName("createBinding1");
+        List<Integer> list = (List<Integer>) getInstance("createBinding1");
         Assert.assertNotNull(list);
         Assert.assertTrue(list.size() == 1);
-        contextFactory.destroyRequestContext(null);
+        getLifecycle().getContextService().endContext(RequestScoped.class, null);
 
         Assert.assertTrue(Disposal1.getDISPOSCALL());
 



Mime
View raw message