You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by ge...@apache.org on 2010/10/01 13:48:45 UTC

svn commit: r1003498 - in /servicemix/smx4/nmr/trunk/nmr/osgi/src: main/java/org/apache/servicemix/nmr/osgi/ test/ test/java/ test/java/org/ test/java/org/apache/ test/java/org/apache/servicemix/ test/java/org/apache/servicemix/nmr/ test/java/org/apach...

Author: gertv
Date: Fri Oct  1 11:48:44 2010
New Revision: 1003498

URL: http://svn.apache.org/viewvc?rev=1003498&view=rev
Log:
SMX4NMR-228: NPE in ExecutorConfigurator when no configuration settings available

Added:
    servicemix/smx4/nmr/trunk/nmr/osgi/src/test/
    servicemix/smx4/nmr/trunk/nmr/osgi/src/test/java/
    servicemix/smx4/nmr/trunk/nmr/osgi/src/test/java/org/
    servicemix/smx4/nmr/trunk/nmr/osgi/src/test/java/org/apache/
    servicemix/smx4/nmr/trunk/nmr/osgi/src/test/java/org/apache/servicemix/
    servicemix/smx4/nmr/trunk/nmr/osgi/src/test/java/org/apache/servicemix/nmr/
    servicemix/smx4/nmr/trunk/nmr/osgi/src/test/java/org/apache/servicemix/nmr/osgi/
    servicemix/smx4/nmr/trunk/nmr/osgi/src/test/java/org/apache/servicemix/nmr/osgi/ExecutorConfiguratorTest.java
Modified:
    servicemix/smx4/nmr/trunk/nmr/osgi/src/main/java/org/apache/servicemix/nmr/osgi/ExecutorConfigurator.java

Modified: servicemix/smx4/nmr/trunk/nmr/osgi/src/main/java/org/apache/servicemix/nmr/osgi/ExecutorConfigurator.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/nmr/osgi/src/main/java/org/apache/servicemix/nmr/osgi/ExecutorConfigurator.java?rev=1003498&r1=1003497&r2=1003498&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/nmr/osgi/src/main/java/org/apache/servicemix/nmr/osgi/ExecutorConfigurator.java (original)
+++ servicemix/smx4/nmr/trunk/nmr/osgi/src/main/java/org/apache/servicemix/nmr/osgi/ExecutorConfigurator.java Fri Oct  1 11:48:44 2010
@@ -44,44 +44,46 @@ public class ExecutorConfigurator implem
     public void updated(Dictionary properties) throws ConfigurationException {
         ExecutorConfig defaultConfig = new ExecutorConfig();
         Map<String, ExecutorConfig> configs = new HashMap<String, ExecutorConfig>();
-        for (Enumeration e = properties.keys(); e.hasMoreElements();) {
-            String key = (String) e.nextElement();
-            if (key.endsWith(".corePoolSize")) {
-                getConfig(configs, key).setCorePoolSize(getInt(properties, key));
-            } else if (key.endsWith(".maximumPoolSize")) {
-                getConfig(configs, key).setMaximumPoolSize(getInt(properties, key));
-            } else if (key.endsWith(".keepAliveTime")) {
-                getConfig(configs, key).setKeepAliveTime(getLong(properties, key));
-            } else if (key.endsWith(".threadDaemon")) {
-                getConfig(configs, key).setThreadDaemon(getBool(properties, key));
-            } else if (key.endsWith(".threadPriority")) {
-                getConfig(configs, key).setThreadPriority(getInt(properties, key));
-            } else if (key.endsWith(".queueSize")) {
-                getConfig(configs, key).setQueueSize(getInt(properties, key));
-            } else if (key.endsWith(".shutdownDelay")) {
-                getConfig(configs, key).setShutdownDelay(getLong(properties, key));
-            } else if (key.endsWith(".allowCoreThreadsTimeout")) {
-                getConfig(configs, key).setAllowCoreThreadsTimeout(getBool(properties, key));
-            } else if (key.endsWith(".bypassIfSynchronous")) {
-                getConfig(configs, key).setBypassIfSynchronous(getBool(properties, key));
-            } else if (key.equals("corePoolSize")) {
-                defaultConfig.setCorePoolSize(getInt(properties, key));
-            } else if (key.equals("maximumPoolSize")) {
-                defaultConfig.setMaximumPoolSize(getInt(properties, key));
-            } else if (key.equals("keepAliveTime")) {
-                defaultConfig.setKeepAliveTime(getLong(properties, key));
-            } else if (key.equals("threadDaemon")) {
-                defaultConfig.setThreadDaemon(getBool(properties, key));
-            } else if (key.equals("threadPriority")) {
-                defaultConfig.setThreadPriority(getInt(properties, key));
-            } else if (key.equals("queueSize")) {
-                defaultConfig.setQueueSize(getInt(properties, key));
-            } else if (key.equals("shutdownDelay")) {
-                defaultConfig.setShutdownDelay(getLong(properties, key));
-            } else if (key.equals("allowCoreThreadsTimeout")) {
-                defaultConfig.setAllowCoreThreadsTimeout(getBool(properties, key));
-            } else if (key.equals("bypassIfSynchronous")) {
-                defaultConfig.setBypassIfSynchronous(getBool(properties, key));
+        if (properties != null) {
+            for (Enumeration e = properties.keys(); e.hasMoreElements();) {
+                String key = (String) e.nextElement();
+                if (key.endsWith(".corePoolSize")) {
+                    getConfig(configs, key).setCorePoolSize(getInt(properties, key));
+                } else if (key.endsWith(".maximumPoolSize")) {
+                    getConfig(configs, key).setMaximumPoolSize(getInt(properties, key));
+                } else if (key.endsWith(".keepAliveTime")) {
+                    getConfig(configs, key).setKeepAliveTime(getLong(properties, key));
+                } else if (key.endsWith(".threadDaemon")) {
+                    getConfig(configs, key).setThreadDaemon(getBool(properties, key));
+                } else if (key.endsWith(".threadPriority")) {
+                    getConfig(configs, key).setThreadPriority(getInt(properties, key));
+                } else if (key.endsWith(".queueSize")) {
+                    getConfig(configs, key).setQueueSize(getInt(properties, key));
+                } else if (key.endsWith(".shutdownDelay")) {
+                    getConfig(configs, key).setShutdownDelay(getLong(properties, key));
+                } else if (key.endsWith(".allowCoreThreadsTimeout")) {
+                    getConfig(configs, key).setAllowCoreThreadsTimeout(getBool(properties, key));
+                } else if (key.endsWith(".bypassIfSynchronous")) {
+                    getConfig(configs, key).setBypassIfSynchronous(getBool(properties, key));
+                } else if (key.equals("corePoolSize")) {
+                    defaultConfig.setCorePoolSize(getInt(properties, key));
+                } else if (key.equals("maximumPoolSize")) {
+                    defaultConfig.setMaximumPoolSize(getInt(properties, key));
+                } else if (key.equals("keepAliveTime")) {
+                    defaultConfig.setKeepAliveTime(getLong(properties, key));
+                } else if (key.equals("threadDaemon")) {
+                    defaultConfig.setThreadDaemon(getBool(properties, key));
+                } else if (key.equals("threadPriority")) {
+                    defaultConfig.setThreadPriority(getInt(properties, key));
+                } else if (key.equals("queueSize")) {
+                    defaultConfig.setQueueSize(getInt(properties, key));
+                } else if (key.equals("shutdownDelay")) {
+                    defaultConfig.setShutdownDelay(getLong(properties, key));
+                } else if (key.equals("allowCoreThreadsTimeout")) {
+                    defaultConfig.setAllowCoreThreadsTimeout(getBool(properties, key));
+                } else if (key.equals("bypassIfSynchronous")) {
+                    defaultConfig.setBypassIfSynchronous(getBool(properties, key));
+                }
             }
         }
         executorFactory.setDefaultConfig(defaultConfig);

Added: servicemix/smx4/nmr/trunk/nmr/osgi/src/test/java/org/apache/servicemix/nmr/osgi/ExecutorConfiguratorTest.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/nmr/osgi/src/test/java/org/apache/servicemix/nmr/osgi/ExecutorConfiguratorTest.java?rev=1003498&view=auto
==============================================================================
--- servicemix/smx4/nmr/trunk/nmr/osgi/src/test/java/org/apache/servicemix/nmr/osgi/ExecutorConfiguratorTest.java (added)
+++ servicemix/smx4/nmr/trunk/nmr/osgi/src/test/java/org/apache/servicemix/nmr/osgi/ExecutorConfiguratorTest.java Fri Oct  1 11:48:44 2010
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.nmr.osgi;
+
+import junit.framework.TestCase;
+import org.apache.servicemix.executors.impl.ExecutorFactoryImpl;
+import org.osgi.service.cm.ConfigurationException;
+
+/**
+ * Test cases for {@link org.apache.servicemix.nmr.osgi.ExecutorConfigurator#updated(java.util.Dictionary)}
+ */
+public class ExecutorConfiguratorTest extends TestCase {
+
+    public void testUpdatedWithNullDictionary() {
+        ExecutorConfigurator configurator = new ExecutorConfigurator();
+        configurator.setExecutorFactory(new ExecutorFactoryImpl());
+        
+        try {
+            configurator.updated(null);
+            // this is OK
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("Should not throw exception: " + e);
+        }
+    }    
+}