Repository: mina-sshd
Updated Branches:
  refs/heads/master 862f4f029 -> 9208a8d26


Replace HashMap with TreeMap in several locations for improved debugging


Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/9208a8d2
Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/9208a8d2
Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/9208a8d2

Branch: refs/heads/master
Commit: 9208a8d26a0bbd6cb37c7b1c33dc28278d0a40e8
Parents: 862f4f0
Author: Goldstein Lyor <l...@c-b4.com>
Authored: Mon Aug 7 11:52:15 2017 +0300
Committer: Goldstein Lyor <l...@c-b4.com>
Committed: Mon Aug 7 11:52:29 2017 +0300

----------------------------------------------------------------------
 .../sshd/common/forward/DefaultTcpipForwarder.java |  9 +++++----
 .../apache/sshd/common/io/mina/MinaService.java    | 12 ++++++++----
 .../sshd/common/util/logging/LoggingUtils.java     |  6 +++---
 .../sshd/server/auth/gss/CredentialHelper.java     | 17 ++++++++---------
 .../sshd/server/subsystem/sftp/SftpSubsystem.java  |  2 +-
 .../sshd/server/auth/BaseAuthenticatorTest.java    |  5 +++--
 .../pubkey/LdapPublickeyAuthenticatorTest.java     |  5 +++--
 7 files changed, 31 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9208a8d2/sshd-core/src/main/java/org/apache/sshd/common/forward/DefaultTcpipForwarder.java
----------------------------------------------------------------------
diff --git 
a/sshd-core/src/main/java/org/apache/sshd/common/forward/DefaultTcpipForwarder.java
 
b/sshd-core/src/main/java/org/apache/sshd/common/forward/DefaultTcpipForwarder.java
index 34341e8..23fe01c 100644
--- 
a/sshd-core/src/main/java/org/apache/sshd/common/forward/DefaultTcpipForwarder.java
+++ 
b/sshd-core/src/main/java/org/apache/sshd/common/forward/DefaultTcpipForwarder.java
@@ -25,12 +25,13 @@ import java.net.SocketAddress;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.Comparator;
 import java.util.EnumSet;
-import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
 import java.util.Objects;
 import java.util.Set;
+import java.util.TreeMap;
 import java.util.concurrent.CopyOnWriteArraySet;
 import java.util.concurrent.TimeUnit;
 
@@ -88,9 +89,9 @@ public class DefaultTcpipForwarder
     private final ConnectionService service;
     private final IoHandlerFactory socksProxyIoHandlerFactory = () -> new 
SocksProxy(getConnectionService());
     private final Session sessionInstance;
-    private final Map<Integer, SshdSocketAddress> localToRemote = new 
HashMap<>();
-    private final Map<Integer, SshdSocketAddress> remoteToLocal = new 
HashMap<>();
-    private final Map<Integer, SocksProxy> dynamicLocal = new HashMap<>();
+    private final Map<Integer, SshdSocketAddress> localToRemote = new 
TreeMap<>(Comparator.naturalOrder());
+    private final Map<Integer, SshdSocketAddress> remoteToLocal = new 
TreeMap<>(Comparator.naturalOrder());
+    private final Map<Integer, SocksProxy> dynamicLocal = new 
TreeMap<>(Comparator.naturalOrder());
     private final Set<LocalForwardingEntry> localForwards = new HashSet<>();
     private final IoHandlerFactory staticIoHandlerFactory = 
StaticIoHandler::new;
     private final Collection<PortForwardingEventListener> listeners = new 
CopyOnWriteArraySet<>();

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9208a8d2/sshd-core/src/main/java/org/apache/sshd/common/io/mina/MinaService.java
----------------------------------------------------------------------
diff --git 
a/sshd-core/src/main/java/org/apache/sshd/common/io/mina/MinaService.java 
b/sshd-core/src/main/java/org/apache/sshd/common/io/mina/MinaService.java
index 2a6ce7d..15c1a7f 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/io/mina/MinaService.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/io/mina/MinaService.java
@@ -18,8 +18,9 @@
  */
 package org.apache.sshd.common.io.mina;
 
-import java.util.HashMap;
+import java.util.Comparator;
 import java.util.Map;
+import java.util.TreeMap;
 
 import org.apache.mina.core.RuntimeIoException;
 import org.apache.mina.core.buffer.IoBuffer;
@@ -67,11 +68,14 @@ public abstract class MinaService extends AbstractCloseable 
implements org.apach
 
     @Override
     public Map<Long, org.apache.sshd.common.io.IoSession> getManagedSessions() 
{
-        Map<Long, IoSession> mina = new 
HashMap<>(getIoService().getManagedSessions());
-        Map<Long, org.apache.sshd.common.io.IoSession> sessions = new 
HashMap<>();
+        IoService ioService = getIoService();
+        Map<Long, IoSession> managedMap = ioService.getManagedSessions();
+        Map<Long, IoSession> mina = new TreeMap<>(managedMap);
+        Map<Long, org.apache.sshd.common.io.IoSession> sessions = new 
TreeMap<>(Comparator.naturalOrder());
         for (Long id : mina.keySet()) {
             // Avoid possible NPE if the MinaSession hasn't been created yet
-            org.apache.sshd.common.io.IoSession session = 
getSession(mina.get(id));
+            IoSession minaSession = mina.get(id);
+            org.apache.sshd.common.io.IoSession session = 
getSession(minaSession);
             if (session != null) {
                 sessions.put(id, session);
             }

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9208a8d2/sshd-core/src/main/java/org/apache/sshd/common/util/logging/LoggingUtils.java
----------------------------------------------------------------------
diff --git 
a/sshd-core/src/main/java/org/apache/sshd/common/util/logging/LoggingUtils.java 
b/sshd-core/src/main/java/org/apache/sshd/common/util/logging/LoggingUtils.java
index 6ba3df0..b8f84cc 100644
--- 
a/sshd-core/src/main/java/org/apache/sshd/common/util/logging/LoggingUtils.java
+++ 
b/sshd-core/src/main/java/org/apache/sshd/common/util/logging/LoggingUtils.java
@@ -24,7 +24,7 @@ import java.lang.reflect.Modifier;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.HashMap;
+import java.util.Comparator;
 import java.util.List;
 import java.util.Map;
 import java.util.Objects;
@@ -82,7 +82,7 @@ public final class LoggingUtils {
             return Collections.emptyMap();
         }
 
-        Map<Integer, String> result = new HashMap<>(fields.size());
+        Map<Integer, String> result = new TreeMap<>(Comparator.naturalOrder());
         for (Field f : fields) {
             String name = f.getName();
             try {
@@ -138,7 +138,7 @@ public final class LoggingUtils {
         }
 
         Map<String, Integer> result = new 
TreeMap<>(String.CASE_INSENSITIVE_ORDER);
-        Map<Integer, List<String>> opcodesMap = new HashMap<>(fields.size());
+        Map<Integer, List<String>> opcodesMap = new 
TreeMap<>(Comparator.naturalOrder());
         for (Field f : fields) {
             String name = f.getName();
             try {

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9208a8d2/sshd-core/src/main/java/org/apache/sshd/server/auth/gss/CredentialHelper.java
----------------------------------------------------------------------
diff --git 
a/sshd-core/src/main/java/org/apache/sshd/server/auth/gss/CredentialHelper.java 
b/sshd-core/src/main/java/org/apache/sshd/server/auth/gss/CredentialHelper.java
index 2e36ab6..f8a9038 100644
--- 
a/sshd-core/src/main/java/org/apache/sshd/server/auth/gss/CredentialHelper.java
+++ 
b/sshd-core/src/main/java/org/apache/sshd/server/auth/gss/CredentialHelper.java
@@ -20,8 +20,8 @@ package org.apache.sshd.server.auth.gss;
 
 import java.security.PrivilegedActionException;
 import java.security.PrivilegedExceptionAction;
-import java.util.HashMap;
 import java.util.Map;
+import java.util.TreeMap;
 
 import javax.security.auth.Subject;
 import javax.security.auth.login.AppConfigurationEntry;
@@ -65,18 +65,17 @@ public final class CredentialHelper {
         private AppConfigurationEntry entry;
 
         private FixedLoginConfiguration(String spn, String keytab) {
-            Map<String, String> parms = new HashMap<>();
-
-            parms.put("isInitiator", "false");
-            parms.put("principal", spn);
-            parms.put("useKeyTab", "true");
-            parms.put("storeKey", "true");
+            Map<String, String> params = new 
TreeMap<>(String.CASE_INSENSITIVE_ORDER);
+            params.put("isInitiator", "false");
+            params.put("principal", spn);
+            params.put("useKeyTab", "true");
+            params.put("storeKey", "true");
 
             if (keytab != null) {
-                parms.put("keyTab", keytab);
+                params.put("keyTab", keytab);
             }
 
-            entry = new 
AppConfigurationEntry("com.sun.security.auth.module.Krb5LoginModule", 
AppConfigurationEntry.LoginModuleControlFlag.REQUIRED, parms);
+            entry = new 
AppConfigurationEntry("com.sun.security.auth.module.Krb5LoginModule", 
AppConfigurationEntry.LoginModuleControlFlag.REQUIRED, params);
         }
 
         @Override

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9208a8d2/sshd-core/src/main/java/org/apache/sshd/server/subsystem/sftp/SftpSubsystem.java
----------------------------------------------------------------------
diff --git 
a/sshd-core/src/main/java/org/apache/sshd/server/subsystem/sftp/SftpSubsystem.java
 
b/sshd-core/src/main/java/org/apache/sshd/server/subsystem/sftp/SftpSubsystem.java
index 8406252..cc66d02 100644
--- 
a/sshd-core/src/main/java/org/apache/sshd/server/subsystem/sftp/SftpSubsystem.java
+++ 
b/sshd-core/src/main/java/org/apache/sshd/server/subsystem/sftp/SftpSubsystem.java
@@ -295,7 +295,7 @@ public class SftpSubsystem
     protected Path defaultDir = 
fileSystem.getPath(System.getProperty("user.dir"));
     protected long requestsCount;
     protected int version;
-    protected final Map<String, byte[]> extensions = new HashMap<>();
+    protected final Map<String, byte[]> extensions = new 
TreeMap<>(Comparator.naturalOrder());
     protected final Map<String, Handle> handles = new HashMap<>();
     protected final UnsupportedAttributePolicy unsupportedAttributePolicy;
 

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9208a8d2/sshd-ldap/src/test/java/org/apache/sshd/server/auth/BaseAuthenticatorTest.java
----------------------------------------------------------------------
diff --git 
a/sshd-ldap/src/test/java/org/apache/sshd/server/auth/BaseAuthenticatorTest.java
 
b/sshd-ldap/src/test/java/org/apache/sshd/server/auth/BaseAuthenticatorTest.java
index 8244ffe..3d6f991 100644
--- 
a/sshd-ldap/src/test/java/org/apache/sshd/server/auth/BaseAuthenticatorTest.java
+++ 
b/sshd-ldap/src/test/java/org/apache/sshd/server/auth/BaseAuthenticatorTest.java
@@ -20,10 +20,11 @@
 package org.apache.sshd.server.auth;
 
 import java.io.File;
-import java.util.HashMap;
+import java.util.Comparator;
 import java.util.List;
 import java.util.Map;
 import java.util.Objects;
+import java.util.TreeMap;
 
 import org.apache.directory.server.constants.ServerDNConstants;
 import org.apache.directory.server.core.CoreSession;
@@ -178,7 +179,7 @@ public abstract class BaseAuthenticatorTest extends 
BaseTestSupport {
     public static Map<String, String> populateUsers(DirectoryService service, 
Class<?> anchor, String credentialName) throws Exception {
         Logger log = LoggerFactory.getLogger(anchor);
         CoreSession session = 
Objects.requireNonNull(service.getAdminSession(), "No core session");
-        Map<String, String> usersMap = new HashMap<>();
+        Map<String, String> usersMap = new 
TreeMap<>(Comparator.naturalOrder());
         try (LdifReader reader = new 
LdifReader(Objects.requireNonNull(anchor.getResourceAsStream("/auth-users.ldif"),
 "No users ldif"))) {
             int id = 1;
             for (LdifEntry entry : reader) {

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9208a8d2/sshd-ldap/src/test/java/org/apache/sshd/server/auth/pubkey/LdapPublickeyAuthenticatorTest.java
----------------------------------------------------------------------
diff --git 
a/sshd-ldap/src/test/java/org/apache/sshd/server/auth/pubkey/LdapPublickeyAuthenticatorTest.java
 
b/sshd-ldap/src/test/java/org/apache/sshd/server/auth/pubkey/LdapPublickeyAuthenticatorTest.java
index 9ae0d3b..f2c7b66 100644
--- 
a/sshd-ldap/src/test/java/org/apache/sshd/server/auth/pubkey/LdapPublickeyAuthenticatorTest.java
+++ 
b/sshd-ldap/src/test/java/org/apache/sshd/server/auth/pubkey/LdapPublickeyAuthenticatorTest.java
@@ -20,9 +20,10 @@
 package org.apache.sshd.server.auth.pubkey;
 
 import java.security.PublicKey;
-import java.util.HashMap;
+import java.util.Comparator;
 import java.util.Map;
 import java.util.Objects;
+import java.util.TreeMap;
 import java.util.concurrent.atomic.AtomicReference;
 
 import org.apache.directory.server.core.DirectoryService;
@@ -47,7 +48,7 @@ import org.mockito.Mockito;
 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
 public class LdapPublickeyAuthenticatorTest extends BaseAuthenticatorTest {
     private static final AtomicReference<Pair<LdapServer, DirectoryService>> 
LDAP_CONTEX_HOLDER = new AtomicReference<>();
-    private static final Map<String, PublicKey> KEYS_MAP = new HashMap<>();
+    private static final Map<String, PublicKey> KEYS_MAP = new 
TreeMap<>(Comparator.naturalOrder());
     // we use this instead of the default since the default requires some 
extra LDIF manipulation which we don't need
     private static final String TEST_ATTR_NAME = "description";
 

Reply via email to