directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cohei...@apache.org
Subject [1/4] directory-kerberos git commit: Minor code refactor in lib
Date Wed, 04 Feb 2015 16:28:14 GMT
Repository: directory-kerberos
Updated Branches:
  refs/heads/master d93c2c65d -> cacd28379


Minor code refactor in lib


Project: http://git-wip-us.apache.org/repos/asf/directory-kerberos/repo
Commit: http://git-wip-us.apache.org/repos/asf/directory-kerberos/commit/ac8f3e9b
Tree: http://git-wip-us.apache.org/repos/asf/directory-kerberos/tree/ac8f3e9b
Diff: http://git-wip-us.apache.org/repos/asf/directory-kerberos/diff/ac8f3e9b

Branch: refs/heads/master
Commit: ac8f3e9b65e350d3fb0c8316db3bb4945be5b65a
Parents: d93c2c6
Author: Colm O hEigeartaigh <coheigea@apache.org>
Authored: Wed Feb 4 12:41:14 2015 +0000
Committer: Colm O hEigeartaigh <coheigea@apache.org>
Committed: Wed Feb 4 12:41:14 2015 +0000

----------------------------------------------------------------------
 .../main/java/org/apache/kerby/config/Conf.java |  1 +
 .../org/apache/kerby/config/ConfigImpl.java     |  4 ++-
 .../org/apache/kerby/config/ConfigObject.java   | 11 ++++--
 .../apache/kerby/config/IniConfigLoader.java    |  4 +++
 .../apache/kerby/config/MapConfigLoader.java    |  4 +--
 .../kerby/config/PropertiesConfigLoader.java    |  3 +-
 .../apache/kerby/config/XmlConfigLoader.java    | 37 ++++++++------------
 .../kerby/transport/tcp/TcpTransport.java       |  4 ++-
 .../kerby/event/network/TestNetworkClient.java  |  6 ++--
 .../apache/kerby/event/tcp/TestTcpClient.java   |  3 +-
 .../apache/kerby/event/udp/TestUdpClient.java   |  3 +-
 .../main/java/org/apache/kerby/pki/Pkix.java    |  4 ++-
 12 files changed, 43 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/ac8f3e9b/lib/kerby-config/src/main/java/org/apache/kerby/config/Conf.java
----------------------------------------------------------------------
diff --git a/lib/kerby-config/src/main/java/org/apache/kerby/config/Conf.java b/lib/kerby-config/src/main/java/org/apache/kerby/config/Conf.java
index 3327fa3..b1afe50 100644
--- a/lib/kerby-config/src/main/java/org/apache/kerby/config/Conf.java
+++ b/lib/kerby-config/src/main/java/org/apache/kerby/config/Conf.java
@@ -76,6 +76,7 @@ public class Conf implements Config {
         try {
             loader = loaderClass.newInstance();
         } catch (Exception e) {
+            logger.error("Failed to create org.haox.config loader for " + loaderClass.getName(),
e);
             throw new RuntimeException("Failed to create org.haox.config loader for " + loaderClass.getName(),
e);
         }
         loader.setResource(resource);

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/ac8f3e9b/lib/kerby-config/src/main/java/org/apache/kerby/config/ConfigImpl.java
----------------------------------------------------------------------
diff --git a/lib/kerby-config/src/main/java/org/apache/kerby/config/ConfigImpl.java b/lib/kerby-config/src/main/java/org/apache/kerby/config/ConfigImpl.java
index 629446e..3648b91 100644
--- a/lib/kerby-config/src/main/java/org/apache/kerby/config/ConfigImpl.java
+++ b/lib/kerby-config/src/main/java/org/apache/kerby/config/ConfigImpl.java
@@ -71,7 +71,9 @@ public class ConfigImpl implements Config {
         if (result == null) {
             for (Config config : configs) {
                 result = config.getString(name);
-                if (result != null) break;
+                if (result != null) {
+                    break;
+                }
             }
         }
 

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/ac8f3e9b/lib/kerby-config/src/main/java/org/apache/kerby/config/ConfigObject.java
----------------------------------------------------------------------
diff --git a/lib/kerby-config/src/main/java/org/apache/kerby/config/ConfigObject.java b/lib/kerby-config/src/main/java/org/apache/kerby/config/ConfigObject.java
index c915af6..536af3e 100644
--- a/lib/kerby-config/src/main/java/org/apache/kerby/config/ConfigObject.java
+++ b/lib/kerby-config/src/main/java/org/apache/kerby/config/ConfigObject.java
@@ -44,7 +44,11 @@ public class ConfigObject {
 	}
 
     public ConfigObject(List<String> values) {
-        this.value = new ArrayList<String>(values);
+        if (values != null) {
+            this.value = new ArrayList<String>(values);
+        } else {
+            this.value = new ArrayList<String>();
+        }
         this.valueType = VALUE_TYPE.LIST;
     }
 
@@ -61,9 +65,10 @@ public class ConfigObject {
 		return result;
 	}
 	
-	public List<String> getListValues() {
+	@SuppressWarnings("unchecked")
+    public List<String> getListValues() {
 		List<String> results = null;
-		if (valueType == VALUE_TYPE.LIST) {
+		if (valueType == VALUE_TYPE.LIST && value instanceof List<?>) {
             results = (List<String>) value;
 		}
 		

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/ac8f3e9b/lib/kerby-config/src/main/java/org/apache/kerby/config/IniConfigLoader.java
----------------------------------------------------------------------
diff --git a/lib/kerby-config/src/main/java/org/apache/kerby/config/IniConfigLoader.java b/lib/kerby-config/src/main/java/org/apache/kerby/config/IniConfigLoader.java
index cf9f56b..f1f5851 100644
--- a/lib/kerby-config/src/main/java/org/apache/kerby/config/IniConfigLoader.java
+++ b/lib/kerby-config/src/main/java/org/apache/kerby/config/IniConfigLoader.java
@@ -48,6 +48,10 @@ public class IniConfigLoader extends ConfigLoader {
     }
 
     private void parseLine(String line) {
+        if (line == null) {
+            return;
+        }
+        
         line = line.trim();
 
         if (line.startsWith(COMMENT_SYMBOL)) {

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/ac8f3e9b/lib/kerby-config/src/main/java/org/apache/kerby/config/MapConfigLoader.java
----------------------------------------------------------------------
diff --git a/lib/kerby-config/src/main/java/org/apache/kerby/config/MapConfigLoader.java b/lib/kerby-config/src/main/java/org/apache/kerby/config/MapConfigLoader.java
index f83517f..734d6a4 100644
--- a/lib/kerby-config/src/main/java/org/apache/kerby/config/MapConfigLoader.java
+++ b/lib/kerby-config/src/main/java/org/apache/kerby/config/MapConfigLoader.java
@@ -24,10 +24,10 @@ import java.util.Map;
 public class MapConfigLoader extends ConfigLoader {
     @Override
     protected void loadConfig(ConfigImpl config, Resource resource) {
+        @SuppressWarnings("unchecked")
         Map<String, String> mapConfig = (Map<String, String>) resource.getResource();
-        String value;
         for (String key : mapConfig.keySet()) {
-            value = mapConfig.get(key);
+            String value = mapConfig.get(key);
             config.set(key, value);
         }
     }

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/ac8f3e9b/lib/kerby-config/src/main/java/org/apache/kerby/config/PropertiesConfigLoader.java
----------------------------------------------------------------------
diff --git a/lib/kerby-config/src/main/java/org/apache/kerby/config/PropertiesConfigLoader.java
b/lib/kerby-config/src/main/java/org/apache/kerby/config/PropertiesConfigLoader.java
index e0b9782..6fe4bf1 100644
--- a/lib/kerby-config/src/main/java/org/apache/kerby/config/PropertiesConfigLoader.java
+++ b/lib/kerby-config/src/main/java/org/apache/kerby/config/PropertiesConfigLoader.java
@@ -30,10 +30,9 @@ public class PropertiesConfigLoader extends ConfigLoader {
     }
 
     protected void loadConfig(ConfigImpl config, Properties propConfig) {
-        Object value;
         for (Object key : propConfig.keySet()) {
             if (key instanceof String) {
-                value = propConfig.getProperty((String) key);
+                Object value = propConfig.getProperty((String) key);
                 if (value != null && value instanceof String) {
                     config.set((String) key, (String) value);
                 }

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/ac8f3e9b/lib/kerby-config/src/main/java/org/apache/kerby/config/XmlConfigLoader.java
----------------------------------------------------------------------
diff --git a/lib/kerby-config/src/main/java/org/apache/kerby/config/XmlConfigLoader.java b/lib/kerby-config/src/main/java/org/apache/kerby/config/XmlConfigLoader.java
index 2208abc..786ac1d 100644
--- a/lib/kerby-config/src/main/java/org/apache/kerby/config/XmlConfigLoader.java
+++ b/lib/kerby-config/src/main/java/org/apache/kerby/config/XmlConfigLoader.java
@@ -75,10 +75,7 @@ public class XmlConfigLoader extends ConfigLoader {
         return valid;
     }
 
-    private void loadConfig(ConfigImpl conifg, Element element) {
-        String name;
-        ConfigObject value;
-
+    private void loadConfig(ConfigImpl config, Element element) {
         NodeList props = element.getChildNodes();
         for (int i = 0; i < props.getLength(); i++) {
             Node subNode = props.item(i);
@@ -87,12 +84,12 @@ public class XmlConfigLoader extends ConfigLoader {
             }
 
             Element prop = (Element)subNode;
-            name = getElementName(prop);
+            String name = getElementName(prop);
             if (name == null) {
                 continue;
             }
 
-            value = null;
+            ConfigObject value = null;
             String tagName = prop.getTagName();
             if ("property".equals(tagName) && prop.hasChildNodes()) {
                 value = loadProperty(prop);
@@ -103,26 +100,25 @@ public class XmlConfigLoader extends ConfigLoader {
             }
 
             if (name != null) {
-                conifg.set(name, value);
+                config.set(name, value);
             }
         }
     }
 
     private static ConfigObject loadProperty(Element ele) {
-        String value = null;
         if (ele.getFirstChild() instanceof Text) {
-            value = ((Text)ele.getFirstChild()).getData();
+            String value = ((Text)ele.getFirstChild()).getData();
             return new ConfigObject(value);
         }
 
-        ConfigObject result = null;
         NodeList nodes = ele.getChildNodes();
         List<String> values = new ArrayList<String>(nodes.getLength());
         for (int i = 0; i < nodes.getLength(); i++) {
-            value = null;
+            String value = null;
             Node valueNode = nodes.item(i);
-            if (!(valueNode instanceof Element))
+            if (!(valueNode instanceof Element)) {
                 continue;
+            }
 
             Element valueEle = (Element)valueNode;
             if ("value".equals(valueEle.getTagName()) && valueEle.hasChildNodes())
{
@@ -137,21 +133,16 @@ public class XmlConfigLoader extends ConfigLoader {
     }
 
     private static String getElementName(Element ele) {
-        String name, value;
-        Node node;
-        Attr attr;
-
         NamedNodeMap nnm = ele.getAttributes();
         for (int i = 0; i < nnm.getLength(); ++i) {
-            node = nnm.item(i);
-            if (!(node instanceof Attr))
+            Node node = nnm.item(i);
+            if (!(node instanceof Attr)) {
                 continue;
-            attr = (Attr) node;
-            name = attr.getName();
-            value = attr.getValue();
+            }
+            Attr attr = (Attr) node;
 
-            if ("name".equals(name)) {
-                return value;
+            if ("name".equals(attr.getName())) {
+                return attr.getValue();
             }
         }
         return null;

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/ac8f3e9b/lib/kerby-event/src/main/java/org/apache/kerby/transport/tcp/TcpTransport.java
----------------------------------------------------------------------
diff --git a/lib/kerby-event/src/main/java/org/apache/kerby/transport/tcp/TcpTransport.java
b/lib/kerby-event/src/main/java/org/apache/kerby/transport/tcp/TcpTransport.java
index a662e38..c09d393 100644
--- a/lib/kerby-event/src/main/java/org/apache/kerby/transport/tcp/TcpTransport.java
+++ b/lib/kerby-event/src/main/java/org/apache/kerby/transport/tcp/TcpTransport.java
@@ -100,7 +100,9 @@ public class TcpTransport extends Transport {
         }
 
         public void handle() {
-            if (recvBuffer.isEmpty()) return;
+            if (recvBuffer.isEmpty()) {
+                return;
+            }
 
             streamingBuffer = recvBuffer.readMostBytes();
 

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/ac8f3e9b/lib/kerby-event/src/test/java/org/apache/kerby/event/network/TestNetworkClient.java
----------------------------------------------------------------------
diff --git a/lib/kerby-event/src/test/java/org/apache/kerby/event/network/TestNetworkClient.java
b/lib/kerby-event/src/test/java/org/apache/kerby/event/network/TestNetworkClient.java
index 10471eb..b52a18d 100644
--- a/lib/kerby-event/src/test/java/org/apache/kerby/event/network/TestNetworkClient.java
+++ b/lib/kerby-event/src/test/java/org/apache/kerby/event/network/TestNetworkClient.java
@@ -80,9 +80,8 @@ public class TestNetworkClient extends TestNetworkBase {
     }
 
     private void doRunTcpServer() throws IOException {
-        ServerSocketChannel serverSocketChannel;
         Selector selector = Selector.open();
-        serverSocketChannel = ServerSocketChannel .open();
+        ServerSocketChannel serverSocketChannel = ServerSocketChannel.open();
         serverSocketChannel.configureBlocking(false);
         ServerSocket serverSocket = serverSocketChannel.socket();
         serverSocket.bind(new InetSocketAddress(tcpPort));
@@ -125,9 +124,8 @@ public class TestNetworkClient extends TestNetworkBase {
     }
 
     private void doRunUdpServer() throws IOException {
-        DatagramChannel serverSocketChannel;
         Selector selector = Selector.open();
-        serverSocketChannel = DatagramChannel.open();
+        DatagramChannel serverSocketChannel = DatagramChannel.open();
         serverSocketChannel.configureBlocking(false);
         DatagramSocket serverSocket = serverSocketChannel.socket();
         serverSocket.bind(new InetSocketAddress(udpPort));

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/ac8f3e9b/lib/kerby-event/src/test/java/org/apache/kerby/event/tcp/TestTcpClient.java
----------------------------------------------------------------------
diff --git a/lib/kerby-event/src/test/java/org/apache/kerby/event/tcp/TestTcpClient.java b/lib/kerby-event/src/test/java/org/apache/kerby/event/tcp/TestTcpClient.java
index 5f03c99..1e895b6 100644
--- a/lib/kerby-event/src/test/java/org/apache/kerby/event/tcp/TestTcpClient.java
+++ b/lib/kerby-event/src/test/java/org/apache/kerby/event/tcp/TestTcpClient.java
@@ -72,9 +72,8 @@ public class TestTcpClient extends TestTcpBase {
     }
 
     private void doRunServer() throws IOException {
-        ServerSocketChannel serverSocketChannel;
         Selector selector = Selector.open();
-        serverSocketChannel = ServerSocketChannel .open();
+        ServerSocketChannel serverSocketChannel = ServerSocketChannel .open();
         serverSocketChannel.configureBlocking(false);
         ServerSocket serverSocket = serverSocketChannel.socket();
         serverSocket.bind(new InetSocketAddress(serverPort));

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/ac8f3e9b/lib/kerby-event/src/test/java/org/apache/kerby/event/udp/TestUdpClient.java
----------------------------------------------------------------------
diff --git a/lib/kerby-event/src/test/java/org/apache/kerby/event/udp/TestUdpClient.java b/lib/kerby-event/src/test/java/org/apache/kerby/event/udp/TestUdpClient.java
index 8c0cd30..d8d5086 100644
--- a/lib/kerby-event/src/test/java/org/apache/kerby/event/udp/TestUdpClient.java
+++ b/lib/kerby-event/src/test/java/org/apache/kerby/event/udp/TestUdpClient.java
@@ -71,9 +71,8 @@ public class TestUdpClient extends TestUdpBase {
     }
 
     private void doRunServer() throws IOException {
-        DatagramChannel serverSocketChannel;
         Selector selector = Selector.open();
-        serverSocketChannel = DatagramChannel.open();
+        DatagramChannel serverSocketChannel = DatagramChannel.open();
         serverSocketChannel.configureBlocking(false);
         DatagramSocket serverSocket = serverSocketChannel.socket();
         serverSocket.bind(new InetSocketAddress(serverPort));

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/ac8f3e9b/lib/kerby-pkix/src/main/java/org/apache/kerby/pki/Pkix.java
----------------------------------------------------------------------
diff --git a/lib/kerby-pkix/src/main/java/org/apache/kerby/pki/Pkix.java b/lib/kerby-pkix/src/main/java/org/apache/kerby/pki/Pkix.java
index e74d74f..5dd66ad 100644
--- a/lib/kerby-pkix/src/main/java/org/apache/kerby/pki/Pkix.java
+++ b/lib/kerby-pkix/src/main/java/org/apache/kerby/pki/Pkix.java
@@ -57,7 +57,9 @@ public class Pkix {
     }
 
     public static PrivateKey getPrivateKey(InputStream inputStream, String password) throws
GeneralSecurityException, IOException {
-        if (password == null) password = "";
+        if (password == null) {
+            password = "";
+        }
         // If the provided InputStream is encrypted, we need a password to decrypt
         // it. If the InputStream is not encrypted, then the password is ignored
         // (can be null).  The InputStream can be DER (raw ASN.1) or PEM (base64).


Mime
View raw message