Author: rmannibucau
Date: Sun Jun  1 12:43:05 2014
New Revision: 1598983

URL: http://svn.apache.org/r1598983
Log:
avoiding NPE when ejb has no webbeanscontext (internal app mainly)

Modified:
    
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/cdi/OWBContextThreadListener.java

Modified: 
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/cdi/OWBContextThreadListener.java
URL: 
http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/cdi/OWBContextThreadListener.java?rev=1598983&r1=1598982&r2=1598983&view=diff
==============================================================================
--- 
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/cdi/OWBContextThreadListener.java
 (original)
+++ 
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/cdi/OWBContextThreadListener.java
 Sun Jun  1 12:43:05 2014
@@ -36,7 +36,7 @@ public class OWBContextThreadListener im
     @Override
     public void contextEntered(final ThreadContext oldContext, final 
ThreadContext newContext) {
         final BeanContext beanContext = newContext.getBeanContext();
-        if (beanContext == null) {
+        if (beanContext == null) { // OWBContextHolder will be null so calling 
contextExited will throw a NPE
             return;
         }
         final ModuleContext moduleContext = beanContext.getModuleContext();
@@ -44,10 +44,12 @@ public class OWBContextThreadListener im
         //For now, go with the attachment of the BeanManager to AppContext
         final AppContext appContext = moduleContext.getAppContext();
         final WebBeansContext owbContext = appContext.getWebBeansContext();
-        if (owbContext == null) {
-            return;
+        final Object oldOWBContext;
+        if (owbContext != null) {
+            oldOWBContext = singletonService.contextEntered(owbContext);
+        } else {
+            oldOWBContext = null;
         }
-        final Object oldOWBContext = 
singletonService.contextEntered(owbContext);
         final OWBContextHolder holder = new OWBContextHolder(oldOWBContext);
         newContext.set(OWBContextHolder.class, holder);
     }
@@ -58,7 +60,11 @@ public class OWBContextThreadListener im
         if (oldOWBContext == null) {
             throw new NullPointerException("OWBContext not set in this 
thread");
         }
-        singletonService.contextExited(oldOWBContext.getContext());
+
+        final Object oldOWBContextContext = oldOWBContext.getContext();
+        if (oldOWBContextContext != null) {
+            singletonService.contextExited(oldOWBContextContext);
+        }
     }
 
     private static final class OWBContextHolder {


Reply via email to