openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1417310 - in /openwebbeans/branches/owb_1.1.x: webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/proxy/ webbeans-impl/src/main/java/org/apache/webbeans/container/ webbeans-impl/src/main/java/org/apache/webbeans/util/
Date Wed, 05 Dec 2012 08:29:42 GMT
Author: rmannibucau
Date: Wed Dec  5 08:29:41 2012
New Revision: 1417310

URL: http://svn.apache.org/viewvc?rev=1417310&view=rev
Log:
OWB-732 ClassLoader leak in WebBeansUtil.isScopeTypeNormalCache. Thanks chunlinyao for the
report! Moving the cache + method over the bean manager to ensure it is done by app.

Modified:
    openwebbeans/branches/owb_1.1.x/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/proxy/EjbBeanProxyHandler.java
    openwebbeans/branches/owb_1.1.x/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
    openwebbeans/branches/owb_1.1.x/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java

Modified: openwebbeans/branches/owb_1.1.x/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/proxy/EjbBeanProxyHandler.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/owb_1.1.x/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/proxy/EjbBeanProxyHandler.java?rev=1417310&r1=1417309&r2=1417310&view=diff
==============================================================================
--- openwebbeans/branches/owb_1.1.x/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/proxy/EjbBeanProxyHandler.java
(original)
+++ openwebbeans/branches/owb_1.1.x/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/proxy/EjbBeanProxyHandler.java
Wed Dec  5 08:29:41 2012
@@ -88,7 +88,7 @@ public class EjbBeanProxyHandler impleme
         this.ejbBean = ejbBean;
         this.webBeansContext = ejbBean.getWebBeansContext();
         
-        if(this.webBeansContext.getWebBeansUtil().isScopeTypeNormal(ejbBean.getScope()))
+        if(this.webBeansContext.getBeanManagerImpl().isScopeTypeNormal(ejbBean.getScope()))
         {
             initiateBeanBag((OwbBean<Object>)ejbBean, (CreationalContext<Object>)creationalContext);
         }

Modified: openwebbeans/branches/owb_1.1.x/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/owb_1.1.x/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java?rev=1417310&r1=1417309&r2=1417310&view=diff
==============================================================================
--- openwebbeans/branches/owb_1.1.x/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
(original)
+++ openwebbeans/branches/owb_1.1.x/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
Wed Dec  5 08:29:41 2012
@@ -203,6 +203,15 @@ public class BeanManagerImpl implements 
 
 
     /**
+     * we cache results of calls to {@link #isScopeTypeNormalCache} because
+     * this doesn't change at runtime.
+     * We don't need to take special care about classloader
+     * hierarchies, because each cl has other classes.
+     */
+    private static Map<Class<? extends Annotation>, Boolean> isScopeTypeNormalCache
=
+            new ConcurrentHashMap<Class<? extends Annotation>, Boolean>();
+
+    /**
      * Creates a new {@link BeanManager} instance.
      * Called by the system. Do not use outside of the
      * system.
@@ -824,7 +833,7 @@ public class BeanManagerImpl implements 
         
                 
         //Scope is normal
-        if (webBeansContext.getWebBeansUtil().isScopeTypeNormal(bean.getScope()))
+        if (isScopeTypeNormal(bean.getScope()))
         {
             instance = getEjbOrJmsProxyReference(bean, beanType,creationalContext);
             
@@ -871,7 +880,7 @@ public class BeanManagerImpl implements 
         //Create session bean proxy
         if(bean instanceof EnterpriseBeanMarker)
         {
-            if(webBeansContext.getWebBeansUtil().isScopeTypeNormal(bean.getScope()))
+            if(isScopeTypeNormal(bean.getScope()))
             {
                 //Maybe it is cached
                 if(cacheProxies.containsKey(bean))
@@ -1127,4 +1136,50 @@ public class BeanManagerImpl implements 
         return inUse;
     }
 
+    /**
+     * The result of this invocation get's cached
+     * @see #isScopeTypeNormalCache
+     * @param scopeType
+     * @return <code>true</code> if the given scopeType represents a
+     *         {@link javax.enterprise.context.NormalScope}d bean
+     */
+    public boolean isScopeTypeNormal(Class<? extends Annotation> scopeType)
+    {
+        Asserts.assertNotNull(scopeType, "scopeType argument can not be null");
+
+        Boolean isNormal = isScopeTypeNormalCache.get(scopeType);
+
+        if (isNormal != null)
+        {
+            return isNormal;
+        }
+
+
+        if (scopeType.isAnnotationPresent(NormalScope.class))
+        {
+            isScopeTypeNormalCache.put(scopeType, Boolean.TRUE);
+            return true;
+        }
+
+        if(scopeType.isAnnotationPresent(Scope.class))
+        {
+            isScopeTypeNormalCache.put(scopeType, Boolean.FALSE);
+            return false;
+        }
+
+        List<ExternalScope> additionalScopes = webBeansContext.getBeanManagerImpl().getAdditionalScopes();
+        for (ExternalScope additionalScope : additionalScopes)
+        {
+            if (additionalScope.getScope().equals(scopeType))
+            {
+                isNormal = additionalScope.isNormal();
+                isScopeTypeNormalCache.put(scopeType, isNormal);
+                return isNormal;
+            }
+        }
+
+        // no scopetype found so far -> kawumms
+        throw new IllegalArgumentException("scopeType argument must be annotated with @Scope
or @NormalScope");
+    }
+
 }

Modified: openwebbeans/branches/owb_1.1.x/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/owb_1.1.x/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java?rev=1417310&r1=1417309&r2=1417310&view=diff
==============================================================================
--- openwebbeans/branches/owb_1.1.x/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
(original)
+++ openwebbeans/branches/owb_1.1.x/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
Wed Dec  5 08:29:41 2012
@@ -38,15 +38,12 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-
 
 import javax.annotation.PostConstruct;
 import javax.annotation.PreDestroy;
 import javax.decorator.Decorator;
 import javax.enterprise.context.Conversation;
 import javax.enterprise.context.Dependent;
-import javax.enterprise.context.NormalScope;
 import javax.enterprise.context.spi.Contextual;
 import javax.enterprise.event.Event;
 import javax.enterprise.event.Observes;
@@ -85,7 +82,6 @@ import javax.enterprise.util.TypeLiteral
 import javax.inject.Inject;
 import javax.inject.Named;
 import javax.inject.Provider;
-import javax.inject.Scope;
 import javax.interceptor.AroundInvoke;
 import javax.interceptor.AroundTimeout;
 import javax.interceptor.InvocationContext;
@@ -125,7 +121,6 @@ import org.apache.webbeans.config.OWBLog
 import org.apache.webbeans.config.OpenWebBeansConfiguration;
 import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.container.BeanManagerImpl;
-import org.apache.webbeans.container.ExternalScope;
 import org.apache.webbeans.container.InjectionResolver;
 import org.apache.webbeans.conversation.ConversationImpl;
 import org.apache.webbeans.decorator.DecoratorUtil;
@@ -1769,7 +1764,7 @@ public final class WebBeansUtil
         Asserts.assertNotNull(scopeType, "scopeType parameter can not be null");
 
         //Unproxiable test for NormalScoped beans
-        if (isScopeTypeNormal(scopeType))
+        if (webBeansContext.getBeanManagerImpl().isScopeTypeNormal(scopeType))
         {
             ViolationMessageBuilder violationMessage = ViolationMessageBuilder.newViolation();
 
@@ -2018,61 +2013,6 @@ public final class WebBeansUtil
             }
         }
     }
-
-    /**
-     * The result of this invocation get's cached
-     * @see #isScopeTypeNormalCache
-     * @param scopeType
-     * @return <code>true</code> if the given scopeType represents a
-     *         {@link javax.enterprise.context.NormalScope}d bean
-     */
-    public boolean isScopeTypeNormal(Class<? extends Annotation> scopeType)
-    {
-        Asserts.assertNotNull(scopeType, "scopeType argument can not be null");
-
-        Boolean isNormal = isScopeTypeNormalCache.get(scopeType);
-
-        if (isNormal != null)
-        {
-            return isNormal.booleanValue();
-        }
-
-
-        if (scopeType.isAnnotationPresent(NormalScope.class))
-        {
-            isScopeTypeNormalCache.put(scopeType, Boolean.TRUE);
-            return true;
-        }
-
-        if(scopeType.isAnnotationPresent(Scope.class))
-        {
-            isScopeTypeNormalCache.put(scopeType, Boolean.FALSE);
-            return false;
-        }
-
-        List<ExternalScope> additionalScopes = webBeansContext.getBeanManagerImpl().getAdditionalScopes();
-        for (ExternalScope additionalScope : additionalScopes)
-        {
-            if (additionalScope.getScope().equals(scopeType))
-            {
-                isNormal = additionalScope.isNormal() ? Boolean.TRUE : Boolean.FALSE;
-                isScopeTypeNormalCache.put(scopeType, isNormal);
-                return isNormal.booleanValue();
-            }
-        }
-
-        // no scopetype found so far -> kawumms
-        throw new IllegalArgumentException("scopeType argument must be annotated with @Scope
or @NormalScope");
-    }
-
-    /**
-     * we cache results of calls to {@link #isScopeTypeNormalCache} because
-     * this doesn't change at runtime.
-     * We don't need to take special care about classloader
-     * hierarchies, because each cl has other classes.
-     */
-    private static Map<Class<? extends Annotation>, Boolean> isScopeTypeNormalCache
=
-            new ConcurrentHashMap<Class<? extends Annotation>, Boolean>();
     
     public static void checkNullInstance(Object instance, Class<? > scopeType, String
errorMessage, 
             Object... errorMessageArgs)



Mime
View raw message