Make isSpringInstrumented test safer
authorMathieu Baudier <mbaudier@argeo.org>
Thu, 28 Jun 2012 14:54:03 +0000 (14:54 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Thu, 28 Jun 2012 14:54:03 +0000 (14:54 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@5390 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/OsgiExecutionModulesManager.java

index 58ae32a655ee9f7f521c98f7473a2a01636b8d03..4ae06f8b3e53bb154a4a91faed1d83be33aea792 100644 (file)
@@ -292,10 +292,7 @@ public class OsgiExecutionModulesManager extends
                        Bundle bundle = bundlesManager.findRelatedBundle(new OsgiBundle(
                                        nameVersion));
                        bundlesManager.startSynchronous(bundle);
-                       boolean isSpringInstrumented = bundle.getEntryPaths(
-                                       "/META-INF/spring").hasMoreElements()
-                                       || bundle.getHeaders().get("Spring-Context") == null;
-                       if (isSpringInstrumented) {
+                       if (isSpringInstrumented(bundle)) {
                                // Wait for Spring application context to be ready
                                String filter = "(Bundle-SymbolicName="
                                                + bundle.getSymbolicName() + ")";
@@ -313,6 +310,18 @@ public class OsgiExecutionModulesManager extends
                }
        }
 
+       /** Do it calmly in order to avoid NPE */
+       private Boolean isSpringInstrumented(Bundle bundle) {
+               Dictionary<?, ?> headers = bundle.getHeaders();
+               if (headers != null && headers.get("Spring-Context") != null)
+                       return true;
+               Enumeration<?> springEntryPaths = bundle
+                               .getEntryPaths("/META-INF/spring");
+               if (springEntryPaths != null && springEntryPaths.hasMoreElements())
+                       return true;
+               return false;
+       }
+
        public void stop(NameVersion nameVersion) {
                try {
                        Bundle bundle = bundlesManager.findRelatedBundle(new OsgiBundle(