This is an automated email from the ASF dual-hosted git repository.

cesarhernandezgt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomee.git


The following commit(s) were added to refs/heads/master by this push:
     new ce5af48  Removed potential NPE.  Fixes TOMEE-1399
     new 05817a1  Merge pull request #675 from davidsalter/TOMEE-1399
ce5af48 is described below

commit ce5af4806e61843b75387fda493825066f01051a
Author: David Salter <[email protected]>
AuthorDate: Fri Jul 10 17:56:08 2020 +0100

    Removed potential NPE.  Fixes TOMEE-1399
---
 .../openejb/assembler/classic/Assembler.java       | 72 +++++++++++-----------
 1 file changed, 37 insertions(+), 35 deletions(-)

diff --git 
a/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
 
b/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
index 0830b1d..f9e33b0 100644
--- 
a/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
+++ 
b/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
@@ -2294,49 +2294,51 @@ public class Assembler extends AssemblerTool implements 
org.apache.openejb.spi.A
 
             final Context globalContext = containerSystem.getJNDIContext();
             final AppContext appContext = 
containerSystem.getAppContext(appInfo.appId);
+
+            if (null == appContext) {
+                logger.warning("Application id '" + appInfo.appId + "' not 
found in: " + Arrays.toString(containerSystem.getAppContextKeys()));
+                return;
+            }
+
             final ClassLoader classLoader = appContext.getClassLoader();
 
             SystemInstance.get().fireEvent(new 
AssemblerBeforeApplicationDestroyed(appInfo, appContext));
 
             //noinspection ConstantConditions
-            if (null == appContext) {
-                logger.warning("Application id '" + appInfo.appId + "' not 
found in: " + Arrays.toString(containerSystem.getAppContextKeys()));
-                return;
-            } else {
-                final WebBeansContext webBeansContext = 
appContext.getWebBeansContext();
-                if (webBeansContext != null) {
-                    final ClassLoader old = 
Thread.currentThread().getContextClassLoader();
-                    Thread.currentThread().setContextClassLoader(classLoader);
-                    try {
-                        final ServletContext context = 
appContext.isStandaloneModule() && 
appContext.getWebContexts().iterator().hasNext() ?
-                                
appContext.getWebContexts().iterator().next().getServletContext() : null;
-                        
webBeansContext.getService(ContainerLifecycle.class).stopApplication(context);
-                    } finally {
-                        Thread.currentThread().setContextClassLoader(old);
-                    }
-                }
-                final Map<String, Object> cb = appContext.getBindings();
-                for (final Entry<String, Object> value : cb.entrySet()) {
-                    String path = value.getKey();
-                    if (path.startsWith("global")) {
-                        path = "java:" + path;
-                    }
-                    if (!path.startsWith("java:global")) {
-                        continue;
-                    }
 
-                    if(IvmContext.class.isInstance(globalContext)) {
-                        
IvmContext.class.cast(globalContext).setReadOnly(false);
-                    }
-                    
-                    unbind(globalContext, path);
-                    unbind(globalContext, "openejb/global/" + 
path.substring("java:".length()));
-                    unbind(globalContext, 
path.substring("java:global".length()));
+            final WebBeansContext webBeansContext = 
appContext.getWebBeansContext();
+            if (webBeansContext != null) {
+                final ClassLoader old = 
Thread.currentThread().getContextClassLoader();
+                Thread.currentThread().setContextClassLoader(classLoader);
+                try {
+                    final ServletContext context = 
appContext.isStandaloneModule() && 
appContext.getWebContexts().iterator().hasNext() ?
+                            
appContext.getWebContexts().iterator().next().getServletContext() : null;
+                    
webBeansContext.getService(ContainerLifecycle.class).stopApplication(context);
+                } finally {
+                    Thread.currentThread().setContextClassLoader(old);
                 }
-                if (appInfo.appId != null && !appInfo.appId.isEmpty() && 
!"openejb".equals(appInfo.appId)) {
-                    unbind(globalContext, "global/" + appInfo.appId);
-                    unbind(globalContext, appInfo.appId);
+            }
+            final Map<String, Object> cb = appContext.getBindings();
+            for (final Entry<String, Object> value : cb.entrySet()) {
+                String path = value.getKey();
+                if (path.startsWith("global")) {
+                    path = "java:" + path;
+                }
+                if (!path.startsWith("java:global")) {
+                    continue;
                 }
+
+                if(IvmContext.class.isInstance(globalContext)) {
+                    IvmContext.class.cast(globalContext).setReadOnly(false);
+                }
+
+                unbind(globalContext, path);
+                unbind(globalContext, "openejb/global/" + 
path.substring("java:".length()));
+                unbind(globalContext, path.substring("java:global".length()));
+            }
+            if (appInfo.appId != null && !appInfo.appId.isEmpty() && 
!"openejb".equals(appInfo.appId)) {
+                unbind(globalContext, "global/" + appInfo.appId);
+                unbind(globalContext, appInfo.appId);
             }
 
             final EjbResolver globalResolver = new EjbResolver(null, 
EjbResolver.Scope.GLOBAL);

Reply via email to