cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sn...@apache.org
Subject [2/3] cassandra git commit: rpc_interface and listen_interface generate NPE on startup when specified interface doesn't exist
Date Tue, 27 Jan 2015 12:38:28 GMT
rpc_interface and listen_interface generate NPE on startup when specified interface doesn't
exist

Patch by Ariel Weisberg; reviewed by Robert Stupp for CASSANDRA-8677


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/3e5edb82
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/3e5edb82
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/3e5edb82

Branch: refs/heads/trunk
Commit: 3e5edb82c73b7b7c6e1d1e970fb764c3e3158da6
Parents: 33297ba
Author: Ariel Weisberg <ariel.weisberg@datastax.com>
Authored: Tue Jan 27 13:30:47 2015 +0100
Committer: Robert Stupp <snazy@snazy.de>
Committed: Tue Jan 27 13:30:47 2015 +0100

----------------------------------------------------------------------
 .../cassandra/config/DatabaseDescriptor.java    | 46 ++++++++++----------
 1 file changed, 23 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/3e5edb82/src/java/org/apache/cassandra/config/DatabaseDescriptor.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/config/DatabaseDescriptor.java b/src/java/org/apache/cassandra/config/DatabaseDescriptor.java
index db33dcc..1dd1688 100644
--- a/src/java/org/apache/cassandra/config/DatabaseDescriptor.java
+++ b/src/java/org/apache/cassandra/config/DatabaseDescriptor.java
@@ -158,6 +158,27 @@ public class DatabaseDescriptor
         return loader.loadConfig();
     }
 
+    private static InetAddress getNetworkInterfaceAddress(String intf, String configName)
throws ConfigurationException
+    {
+        try
+        {
+            NetworkInterface ni = NetworkInterface.getByName(intf);
+            if (ni == null)
+                throw new ConfigurationException("Configured " + configName + " \"" + intf
+ "\" could not be found");
+            Enumeration<InetAddress> addrs = ni.getInetAddresses();
+            if (!addrs.hasMoreElements())
+                throw new ConfigurationException("Configured " + configName + " \"" + intf
+ "\" was found, but had no addresses");
+            InetAddress retval = listenAddress = addrs.nextElement();
+            if (addrs.hasMoreElements())
+                throw new ConfigurationException("Configured " + configName + " \"" + intf
+ "\" can't have more than one address");
+            return retval;
+        }
+        catch (SocketException e)
+        {
+            throw new ConfigurationException("Configured " + configName + " \"" + intf +
"\" caused an exception", e);
+        }
+    }
+
     private static void applyConfig(Config config) throws ConfigurationException
     {
         conf = config;
@@ -326,18 +347,7 @@ public class DatabaseDescriptor
         }
         else if (conf.listen_interface != null)
         {
-            try
-            {
-                Enumeration<InetAddress> addrs = NetworkInterface.getByName(conf.listen_interface).getInetAddresses();
-                listenAddress = addrs.nextElement();
-                if (addrs.hasMoreElements())
-                    throw new ConfigurationException("Interface " + conf.listen_interface
+" can't have more than one address");
-            }
-            catch (SocketException e)
-            {
-                throw new ConfigurationException("Unknown network interface in listen_interface
" + conf.listen_interface);
-            }
-
+            listenAddress = getNetworkInterfaceAddress(conf.listen_interface, "listen_interface");
         }
 
         /* Gossip Address to broadcast */
@@ -374,17 +384,7 @@ public class DatabaseDescriptor
         }
         else if (conf.rpc_interface != null)
         {
-            try
-            {
-                Enumeration<InetAddress> addrs = NetworkInterface.getByName(conf.rpc_interface).getInetAddresses();
-                rpcAddress = addrs.nextElement();
-                if (addrs.hasMoreElements())
-                    throw new ConfigurationException("Interface " + conf.rpc_interface +"
can't have more than one address");
-            }
-            catch (SocketException e)
-            {
-                throw new ConfigurationException("Unknown network interface in rpc_interface
" + conf.rpc_interface);
-            }
+            listenAddress = getNetworkInterfaceAddress(conf.rpc_interface, "rpc_interface");
         }
         else
         {


Mime
View raw message