You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by cs...@apache.org on 2012/11/01 19:31:20 UTC
svn commit: r1404713 -
/cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/ZookeeperStarter.java
Author: cschneider
Date: Thu Nov 1 18:31:19 2012
New Revision: 1404713
URL: http://svn.apache.org/viewvc?rev=1404713&view=rev
Log:
DOSGI-136 Avoid NumberFormatException for empty values
Modified:
cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/ZookeeperStarter.java
Modified: cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/ZookeeperStarter.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/ZookeeperStarter.java?rev=1404713&r1=1404712&r2=1404713&view=diff
==============================================================================
--- cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/ZookeeperStarter.java (original)
+++ cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/ZookeeperStarter.java Thu Nov 1 18:31:19 2012
@@ -19,8 +19,10 @@ package org.apache.cxf.dosgi.discovery.z
import java.io.File;
import java.io.IOException;
+import java.util.ArrayList;
import java.util.Dictionary;
import java.util.Enumeration;
+import java.util.List;
import java.util.Properties;
import org.apache.log4j.Level;
@@ -59,8 +61,8 @@ public class ZookeeperStarter implements
}
}
- @SuppressWarnings("rawtypes")
- public void setDefaults(Dictionary dict) throws IOException {
+ public void setDefaults(Dictionary<String, Object> dict) throws IOException {
+ removeEmptyValues(dict);
setDefault(dict, "tickTime", "2000");
setDefault(dict, "initLimit", "10");
setDefault(dict, "syncLimit", "5");
@@ -68,6 +70,26 @@ public class ZookeeperStarter implements
setDefault(dict, "dataDir", new File(bundleContext.getDataFile(""), "zkdata").getCanonicalPath());
}
+ /**
+ * Remove empty values to avoid NumberFormatExceptions
+ *
+ * @param dict
+ */
+ private void removeEmptyValues(Dictionary<String, Object> dict) {
+ List<String> keysToRemove = new ArrayList<String>();
+ Enumeration<String> keys = dict.keys();
+ while (keys.hasMoreElements()) {
+ String key = keys.nextElement();
+ Object value = dict.get(key);
+ if (value != null && value instanceof String && "".equals(value)) {
+ keysToRemove.add(key);
+ }
+ }
+ for (String key : keysToRemove) {
+ dict.remove(key);
+ }
+ }
+
@SuppressWarnings({ "rawtypes", "unchecked" })
private void setDefault(Dictionary dict, String key, String value) {
if (dict.get(key) == null) {
@@ -75,7 +97,7 @@ public class ZookeeperStarter implements
}
}
- @SuppressWarnings("rawtypes")
+ @SuppressWarnings({ "rawtypes", "unchecked" })
public synchronized void updated(Dictionary dict) throws ConfigurationException {
shutdown();
if (dict == null) {