You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by lg...@apache.org on 2018/04/26 11:15:47 UTC

[2/2] mina-sshd git commit: Activated a few more PMD rules

Activated a few more PMD rules


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

Branch: refs/heads/master
Commit: 93604f76d476c0f8384b0ac81effe8e99b18e1d3
Parents: cda53d6
Author: Goldstein Lyor <ly...@c-b4.com>
Authored: Thu Apr 26 13:47:37 2018 +0300
Committer: Goldstein Lyor <ly...@c-b4.com>
Committed: Thu Apr 26 14:15:40 2018 +0300

----------------------------------------------------------------------
 .../apache/sshd/cli/client/SftpCommandMain.java |  4 +-
 .../sshd/agent/unix/AgentServerProxy.java       | 72 +++++++++-------
 .../apache/sshd/common/channel/SttySupport.java | 10 +--
 .../org/apache/sshd/common/channel/Window.java  |  2 +-
 .../sshd/common/config/TimeValueConfig.java     |  2 +-
 .../server/session/ServerUserAuthService.java   |  4 +-
 .../sshd/server/shell/InvertedShellWrapper.java |  2 +-
 .../java/org/apache/sshd/client/ClientTest.java |  6 +-
 .../hosts/ConfigFileHostEntryResolverTest.java  |  4 +-
 .../hosts/HostConfigEntryResolverTest.java      | 26 +++---
 .../config/hosts/HostConfigEntryTest.java       | 24 +++---
 .../org/apache/sshd/client/kex/KexTest.java     |  2 +-
 .../sshd/common/PropertyResolverUtilsTest.java  |  6 +-
 .../sshd/common/util/SelectorUtilsTest.java     |  6 +-
 sshd-pmd-ruleset.xml                            | 90 +++++++++++++-------
 .../org/apache/sshd/client/scp/ScpClient.java   |  2 +-
 .../org/apache/sshd/common/scp/ScpHelper.java   | 12 ++-
 .../org/apache/sshd/common/scp/ScpLocation.java |  7 +-
 .../client/subsystem/sftp/SftpFileSystem.java   |  2 +-
 19 files changed, 166 insertions(+), 117 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/93604f76/sshd-cli/src/main/java/org/apache/sshd/cli/client/SftpCommandMain.java
----------------------------------------------------------------------
diff --git a/sshd-cli/src/main/java/org/apache/sshd/cli/client/SftpCommandMain.java b/sshd-cli/src/main/java/org/apache/sshd/cli/client/SftpCommandMain.java
index 21b308c..e730448 100644
--- a/sshd-cli/src/main/java/org/apache/sshd/cli/client/SftpCommandMain.java
+++ b/sshd-cli/src/main/java/org/apache/sshd/cli/client/SftpCommandMain.java
@@ -628,7 +628,7 @@ public class SftpCommandMain extends SshClientCliSupport implements Channel {
                             verbose = true;
                             break;
                         default:
-                            throw new IllegalArgumentException("Unknown flag (" + String.valueOf(ch) + ")");
+                            throw new IllegalArgumentException("Unknown flag (" + Character.toString(ch) + ")");
                     }
                 }
                 remotePath = comps[1];
@@ -927,7 +927,7 @@ public class SftpCommandMain extends SshClientCliSupport implements Channel {
                             verbose = true;
                             break;
                         default:
-                            throw new IllegalArgumentException("Unknown flag (" + String.valueOf(ch) + ")");
+                            throw new IllegalArgumentException("Unknown flag (" + Character.toString(ch) + ")");
                     }
                 }
                 src = comps[1];

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/93604f76/sshd-core/src/main/java/org/apache/sshd/agent/unix/AgentServerProxy.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/agent/unix/AgentServerProxy.java b/sshd-core/src/main/java/org/apache/sshd/agent/unix/AgentServerProxy.java
index 7e69486..5b66e57 100644
--- a/sshd-core/src/main/java/org/apache/sshd/agent/unix/AgentServerProxy.java
+++ b/sshd-core/src/main/java/org/apache/sshd/agent/unix/AgentServerProxy.java
@@ -159,28 +159,11 @@ public class AgentServerProxy extends AbstractLoggingBean implements SshAgentSer
         if (handle != 0) {
             if (!innerFinished.get()) {
                 try {
-
-                    final long tmpPool = Pool.create(AprLibrary.getInstance().getRootPool());
-                    final long tmpSocket = Local.create(authSocket, tmpPool);
-                    long connectResult = Local.connect(tmpSocket, 0L);
-
-                    if (connectResult != Status.APR_SUCCESS) {
-                        if (debugEnabled) {
-                            log.debug("Unable to connect to socket PIPE {}. APR errcode {}", authSocket, connectResult);
-                        }
-                    }
-
-                    //write a single byte -- just wake up the accept()
-                    int sendResult = Socket.send(tmpSocket, END_OF_STREAM_MESSAGE, 0, 1);
-                    if (sendResult != 1) {
-                        if (debugEnabled) {
-                            log.debug("Unable to send signal the EOS for {}. APR retcode {} != 1", authSocket, sendResult);
-                        }
-                    }
+                    signalEOS(AprLibrary.getInstance(), debugEnabled);
                 } catch (Exception e) {
                     //log eventual exceptions in debug mode
                     if (debugEnabled) {
-                        log.debug("Exception connecting to the PIPE socket: " + authSocket, e);
+                        log.debug("Exception signalling EOS to the PIPE socket: " + authSocket, e);
                     }
                 }
             }
@@ -193,14 +176,7 @@ public class AgentServerProxy extends AbstractLoggingBean implements SshAgentSer
 
         try {
             if (authSocket != null) {
-                File socketFile = new File(authSocket);
-                if (socketFile.exists()) {
-                    deleteFile(socketFile, "Deleted PIPE socket {}");
-
-                    if (OsUtils.isUNIX()) {
-                        deleteFile(socketFile.getParentFile(), "Deleted parent PIPE socket {}");
-                    }
-                }
+                removeSocketFile(authSocket, debugEnabled);
             }
         } catch (Exception e) {
             //log eventual exceptions in debug mode
@@ -226,12 +202,48 @@ public class AgentServerProxy extends AbstractLoggingBean implements SshAgentSer
         }
     }
 
-    protected void deleteFile(File file, String msg) {
-        if (file.delete()) {
-            if (log.isDebugEnabled()) {
+    protected File removeSocketFile(String socketPath, boolean debugEnabled) throws Exception {
+        File socketFile = new File(socketPath);
+        if (socketFile.exists()) {
+            deleteFile(socketFile, "Deleted PIPE socket {}", debugEnabled);
+
+            if (OsUtils.isUNIX()) {
+                deleteFile(socketFile.getParentFile(), "Deleted parent PIPE socket {}", debugEnabled);
+            }
+        }
+
+        return socketFile;
+    }
+
+    protected void signalEOS(AprLibrary libInstance, boolean debugEnabled) throws Exception {
+        long tmpPool = Pool.create(libInstance.getRootPool());
+        long tmpSocket = Local.create(authSocket, tmpPool);
+        long connectResult = Local.connect(tmpSocket, 0L);
+
+        if (connectResult != Status.APR_SUCCESS) {
+            if (debugEnabled) {
+                log.debug("Unable to connect to socket PIPE {}. APR errcode {}", authSocket, connectResult);
+            }
+        }
+
+        // write a single byte -- just wake up the accept()
+        int sendResult = Socket.send(tmpSocket, END_OF_STREAM_MESSAGE, 0, 1);
+        if (sendResult != 1) {
+            if (debugEnabled) {
+                log.debug("Unable to send signal the EOS for {}. APR retcode {} != 1", authSocket, sendResult);
+            }
+        }
+    }
+
+    protected boolean deleteFile(File file, String msg, boolean debugEnabled) {
+        boolean success = file.delete();
+        if (success) {
+            if (debugEnabled) {
                 log.debug(msg, file);
             }
         }
+
+        return success;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/93604f76/sshd-core/src/main/java/org/apache/sshd/common/channel/SttySupport.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/channel/SttySupport.java b/sshd-core/src/main/java/org/apache/sshd/common/channel/SttySupport.java
index 05cbfbf..da023df 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/channel/SttySupport.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/channel/SttySupport.java
@@ -186,8 +186,7 @@ public final class SttySupport {
         }
     }
 
-    private static int getTerminalProperty(String prop)
-            throws IOException, InterruptedException {
+    public static int getTerminalProperty(String prop) throws IOException, InterruptedException {
         // need to be able handle both output formats:
         // speed 9600 baud; 24 rows; 140 columns;
         // and:
@@ -196,11 +195,11 @@ public final class SttySupport {
             String str = tok.nextToken().trim();
 
             if (str.startsWith(prop)) {
-                int index = str.lastIndexOf(" ");
+                int index = str.lastIndexOf(' ');
 
                 return Integer.parseInt(str.substring(index).trim());
             } else if (str.endsWith(prop)) {
-                int index = str.indexOf(" ");
+                int index = str.indexOf(' ');
 
                 return Integer.parseInt(str.substring(0, index).trim());
             }
@@ -231,8 +230,7 @@ public final class SttySupport {
      * @throws InterruptedException If interrupted while awaiting command execution
      * @see #exec(String)
      */
-    public static String stty(final String args)
-            throws IOException, InterruptedException {
+    public static String stty(String args) throws IOException, InterruptedException {
         return exec("stty " + args + " < /dev/tty").trim();
     }
 

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/93604f76/sshd-core/src/main/java/org/apache/sshd/common/channel/Window.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/channel/Window.java b/sshd-core/src/main/java/org/apache/sshd/common/channel/Window.java
index 5eebb4b..4f6d318 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/channel/Window.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/channel/Window.java
@@ -338,6 +338,6 @@ public class Window extends AbstractLoggingBean implements java.nio.channels.Cha
 
     @Override
     public String toString() {
-        return getClass().getSimpleName() + "[" + suffix + "](" + String.valueOf(getChannel()) + ")";
+        return getClass().getSimpleName() + "[" + suffix + "](" + getChannel() + ")";
     }
 }

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/93604f76/sshd-core/src/main/java/org/apache/sshd/common/config/TimeValueConfig.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/config/TimeValueConfig.java b/sshd-core/src/main/java/org/apache/sshd/common/config/TimeValueConfig.java
index 519b3d1..222cf84 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/config/TimeValueConfig.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/config/TimeValueConfig.java
@@ -115,7 +115,7 @@ public enum TimeValueConfig {
 
             TimeValueConfig c = fromValueChar(ch);
             if (c == null) {
-                throw new IllegalArgumentException("parse(" + s + ") unknown time value character: " + String.valueOf(ch));
+                throw new IllegalArgumentException("parse(" + s + ") unknown time value character: '" + ch + "'");
             }
 
             String v = s.substring(lastPos, curPos);

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/93604f76/sshd-core/src/main/java/org/apache/sshd/server/session/ServerUserAuthService.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/session/ServerUserAuthService.java b/sshd-core/src/main/java/org/apache/sshd/server/session/ServerUserAuthService.java
index 2c72b6d..35a3470 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/session/ServerUserAuthService.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/session/ServerUserAuthService.java
@@ -348,7 +348,7 @@ public class ServerUserAuthService extends AbstractCloseable implements Service,
         String username = (currentAuth == null) ? null : currentAuth.getUsername();
         if (debugEnabled) {
             log.debug("handleAuthenticationFailure({}@{}) {}",
-                      username, session, SshConstants.getCommandMessageName(cmd));
+                  username, session, SshConstants.getCommandMessageName(cmd));
         }
 
         StringBuilder sb = new StringBuilder((authMethods.size() + 1) * Byte.SIZE);
@@ -357,7 +357,7 @@ public class ServerUserAuthService extends AbstractCloseable implements Service,
                 String m = l.get(0);
                 if (!UserAuthNoneFactory.NAME.equals(m)) {
                     if (sb.length() > 0) {
-                        sb.append(",");
+                        sb.append(',');
                     }
                     sb.append(m);
                 }

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/93604f76/sshd-core/src/main/java/org/apache/sshd/server/shell/InvertedShellWrapper.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/shell/InvertedShellWrapper.java b/sshd-core/src/main/java/org/apache/sshd/server/shell/InvertedShellWrapper.java
index 90a9200..4819064 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/shell/InvertedShellWrapper.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/shell/InvertedShellWrapper.java
@@ -257,6 +257,6 @@ public class InvertedShellWrapper extends AbstractLoggingBean implements Command
 
     @Override
     public String toString() {
-        return getClass().getSimpleName() + ": " + String.valueOf(shell);
+        return getClass().getSimpleName() + ": " + shell;
     }
 }

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/93604f76/sshd-core/src/test/java/org/apache/sshd/client/ClientTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/ClientTest.java b/sshd-core/src/test/java/org/apache/sshd/client/ClientTest.java
index 0ae2f11..f3d94a8 100644
--- a/sshd-core/src/test/java/org/apache/sshd/client/ClientTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/client/ClientTest.java
@@ -651,7 +651,7 @@ public class ClientTest extends BaseTestSupport {
                 for (int i = 0; i < 1000; i++) {
                     sb.append("0123456789");
                 }
-                sb.append("\n");
+                sb.append('\n');
                 teeOut.write(sb.toString().getBytes(StandardCharsets.UTF_8));
 
                 teeOut.write("exit\n".getBytes(StandardCharsets.UTF_8));
@@ -695,7 +695,7 @@ public class ClientTest extends BaseTestSupport {
                 for (int i = 0; i < 1000; i++) {
                     sb.append("0123456789");
                 }
-                sb.append("\n");
+                sb.append('\n');
                 pipedIn.write(sb.toString().getBytes(StandardCharsets.UTF_8));
 
                 pipedIn.write("exit\n".getBytes(StandardCharsets.UTF_8));
@@ -764,7 +764,7 @@ public class ClientTest extends BaseTestSupport {
                 for (int i = 0; i < 1000; i++) {
                     sb.append("0123456789");
                 }
-                sb.append("\n");
+                sb.append('\n');
                 teeOut.write(sb.toString().getBytes(StandardCharsets.UTF_8));
             }
 

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/93604f76/sshd-core/src/test/java/org/apache/sshd/client/config/hosts/ConfigFileHostEntryResolverTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/config/hosts/ConfigFileHostEntryResolverTest.java b/sshd-core/src/test/java/org/apache/sshd/client/config/hosts/ConfigFileHostEntryResolverTest.java
index b7afea1..78994cc 100644
--- a/sshd-core/src/test/java/org/apache/sshd/client/config/hosts/ConfigFileHostEntryResolverTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/client/config/hosts/ConfigFileHostEntryResolverTest.java
@@ -74,7 +74,7 @@ public class ConfigFileHostEntryResolverTest extends BaseTestSupport {
                                 1234,
                                 getClass().getSimpleName()),
                         new HostConfigEntry(
-                                expected.getHost() + String.valueOf(HostPatternsHolder.WILDCARD_PATTERN),
+                                expected.getHost() + Character.toString(HostPatternsHolder.WILDCARD_PATTERN),
                                 expected.getHost(),
                                 expected.getPort(),
                                 expected.getUsername())),
@@ -87,7 +87,7 @@ public class ConfigFileHostEntryResolverTest extends BaseTestSupport {
                                 1234,
                                 getClass().getSimpleName()),
                         new HostConfigEntry(
-                                getClass().getSimpleName() + String.valueOf(HostPatternsHolder.WILDCARD_PATTERN),
+                                getClass().getSimpleName() + Character.toString(HostPatternsHolder.WILDCARD_PATTERN),
                                 getClass().getSimpleName(),
                                 1234,
                                 getClass().getSimpleName()),

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/93604f76/sshd-core/src/test/java/org/apache/sshd/client/config/hosts/HostConfigEntryResolverTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/config/hosts/HostConfigEntryResolverTest.java b/sshd-core/src/test/java/org/apache/sshd/client/config/hosts/HostConfigEntryResolverTest.java
index 9871ed5..ab3c591 100644
--- a/sshd-core/src/test/java/org/apache/sshd/client/config/hosts/HostConfigEntryResolverTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/client/config/hosts/HostConfigEntryResolverTest.java
@@ -109,13 +109,13 @@ public class HostConfigEntryResolverTest extends BaseTestSupport {
     public void testNegatedHostEntriesResolution() throws Exception {
         HostConfigEntry positiveEntry = new HostConfigEntry(TEST_LOCALHOST, TEST_LOCALHOST, port, getCurrentTestName());
         HostConfigEntry negativeEntry = new HostConfigEntry(
-                String.valueOf(HostPatternsHolder.NEGATION_CHAR_PATTERN) + positiveEntry.getHost(),
+                Character.toString(HostPatternsHolder.NEGATION_CHAR_PATTERN) + positiveEntry.getHost(),
                 positiveEntry.getHostName(),
                 getMovedPortNumber(positiveEntry.getPort()),
                 getClass().getPackage().getName());
         client.setHostConfigEntryResolver(
                 HostConfigEntry.toHostConfigEntryResolver(
-                        Arrays.asList(negativeEntry, positiveEntry)));
+                    Arrays.asList(negativeEntry, positiveEntry)));
         client.start();
 
         try (ClientSession session = client.connect(
@@ -132,8 +132,8 @@ public class HostConfigEntryResolverTest extends BaseTestSupport {
 
     @Test
     public void testPreloadedIdentities() throws Exception {
-        final KeyPair identity = Utils.getFirstKeyPair(sshd);
-        final String user = getCurrentTestName();
+        KeyPair identity = Utils.getFirstKeyPair(sshd);
+        String user = getCurrentTestName();
         // make sure authentication is achieved only via the identity public key
         sshd.setPublickeyAuthenticator((username, key, session) -> {
             if (user.equals(username)) {
@@ -144,7 +144,7 @@ public class HostConfigEntryResolverTest extends BaseTestSupport {
         });
         sshd.setPasswordAuthenticator(RejectAllPasswordAuthenticator.INSTANCE);
 
-        final String clientIdentity = getCurrentTestName();
+        String clientIdentity = getCurrentTestName();
         client.setClientIdentityLoader(new ClientIdentityLoader() {
             @Override
             public boolean isValidLocation(String location) throws IOException {
@@ -163,8 +163,8 @@ public class HostConfigEntryResolverTest extends BaseTestSupport {
         });
         PropertyResolverUtils.updateProperty(client, ClientFactoryManager.IGNORE_INVALID_IDENTITIES, false);
 
-        final String host = getClass().getSimpleName();
-        final HostConfigEntry entry = new HostConfigEntry(host, TEST_LOCALHOST, port, user);
+        String host = getClass().getSimpleName();
+        HostConfigEntry entry = new HostConfigEntry(host, TEST_LOCALHOST, port, user);
         entry.addIdentity(clientIdentity);
         client.setHostConfigEntryResolver((host1, portValue, username) -> entry);
 
@@ -184,14 +184,14 @@ public class HostConfigEntryResolverTest extends BaseTestSupport {
         KeyPairProvider clientIdProvider =
                 Utils.createTestHostKeyProvider(clientIdFile.resolve(getCurrentTestName() + ".pem"));
 
-        final KeyPair specificIdentity = Utils.getFirstKeyPair(sshd);
-        final KeyPair defaultIdentity = Utils.getFirstKeyPair(clientIdProvider);
+        KeyPair specificIdentity = Utils.getFirstKeyPair(sshd);
+        KeyPair defaultIdentity = Utils.getFirstKeyPair(clientIdProvider);
         ValidateUtils.checkTrue(!KeyUtils.compareKeyPairs(specificIdentity, defaultIdentity),
                 "client identity not different then entry one");
         client.setKeyPairProvider(clientIdProvider);
 
-        final String user = getCurrentTestName();
-        final AtomicBoolean defaultClientIdentityAttempted = new AtomicBoolean(false);
+        String user = getCurrentTestName();
+        AtomicBoolean defaultClientIdentityAttempted = new AtomicBoolean(false);
         // make sure authentication is achieved only via the identity public key
         sshd.setPublickeyAuthenticator((username, key, session) -> {
             if (KeyUtils.compareKeys(defaultIdentity.getPublic(), key)) {
@@ -206,7 +206,7 @@ public class HostConfigEntryResolverTest extends BaseTestSupport {
         });
         sshd.setPasswordAuthenticator(RejectAllPasswordAuthenticator.INSTANCE);
 
-        final String clientIdentity = getCurrentTestName();
+        String clientIdentity = getCurrentTestName();
         HostConfigEntry entry = new HostConfigEntry(TEST_LOCALHOST, TEST_LOCALHOST, port, user);
         entry.addIdentity(clientIdentity);
         entry.setIdentitiesOnly(true);
@@ -229,7 +229,7 @@ public class HostConfigEntryResolverTest extends BaseTestSupport {
         });
         PropertyResolverUtils.updateProperty(client, ClientFactoryManager.IGNORE_INVALID_IDENTITIES, false);
 
-        final Collection<KeyPair> clientIdentities = Collections.singletonList(defaultIdentity);
+        Collection<KeyPair> clientIdentities = Collections.singletonList(defaultIdentity);
         KeyPairProvider provider = new AbstractKeyPairProvider() {
             @Override
             public Iterable<KeyPair> loadKeys() {

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/93604f76/sshd-core/src/test/java/org/apache/sshd/client/config/hosts/HostConfigEntryTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/config/hosts/HostConfigEntryTest.java b/sshd-core/src/test/java/org/apache/sshd/client/config/hosts/HostConfigEntryTest.java
index cf1dafd..c306800 100644
--- a/sshd-core/src/test/java/org/apache/sshd/client/config/hosts/HostConfigEntryTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/client/config/hosts/HostConfigEntryTest.java
@@ -52,7 +52,7 @@ public class HostConfigEntryTest extends BaseTestSupport {
         StringBuilder sb = new StringBuilder(testHost.length() + Byte.SIZE);
         List<HostPatternValue> patterns = new ArrayList<>(elements.length + 1);
         // all wildcard patterns are not negated - only the actual host
-        patterns.add(HostPatternsHolder.toPattern(String.valueOf(HostPatternsHolder.NEGATION_CHAR_PATTERN) + testHost));
+        patterns.add(HostPatternsHolder.toPattern(Character.toString(HostPatternsHolder.NEGATION_CHAR_PATTERN) + testHost));
 
         for (int i = 0; i < elements.length; i++) {
             sb.setLength(0);
@@ -161,19 +161,19 @@ public class HostConfigEntryTest extends BaseTestSupport {
         }
 
         for (char ch = 'a'; ch <= 'z'; ch++) {
-            assertTrue("Valid character not recognized: " + String.valueOf(ch), HostPatternsHolder.isValidPatternChar(ch));
+            assertTrue("Valid character not recognized: " + Character.toString(ch), HostPatternsHolder.isValidPatternChar(ch));
         }
 
         for (char ch = 'A'; ch <= 'Z'; ch++) {
-            assertTrue("Valid character not recognized: " + String.valueOf(ch), HostPatternsHolder.isValidPatternChar(ch));
+            assertTrue("Valid character not recognized: " + Character.toString(ch), HostPatternsHolder.isValidPatternChar(ch));
         }
 
         for (char ch = '0'; ch <= '9'; ch++) {
-            assertTrue("Valid character not recognized: " + String.valueOf(ch), HostPatternsHolder.isValidPatternChar(ch));
+            assertTrue("Valid character not recognized: " + Character.toString(ch), HostPatternsHolder.isValidPatternChar(ch));
         }
 
         for (char ch : new char[] {'-', '_', '.', HostPatternsHolder.SINGLE_CHAR_PATTERN, HostPatternsHolder.WILDCARD_PATTERN}) {
-            assertTrue("Valid character not recognized: " + String.valueOf(ch), HostPatternsHolder.isValidPatternChar(ch));
+            assertTrue("Valid character not recognized: " + Character.toString(ch), HostPatternsHolder.isValidPatternChar(ch));
         }
 
         for (char ch : new char[] {
@@ -181,7 +181,7 @@ public class HostConfigEntryTest extends BaseTestSupport {
             '#', '$', '^', '&', '%', '~', '<', '>',
             ',', '/', '\\', '\'', '"', ':', ';'
         }) {
-            assertFalse("Unexpected valid character: " + String.valueOf(ch), HostPatternsHolder.isValidPatternChar(ch));
+            assertFalse("Unexpected valid character: " + Character.toString(ch), HostPatternsHolder.isValidPatternChar(ch));
         }
 
         for (char ch = 0x7E; ch <= 0xFF; ch++) {
@@ -194,11 +194,11 @@ public class HostConfigEntryTest extends BaseTestSupport {
         final int originalPort = Short.MAX_VALUE;
         final int preferredPort = 7365;
         assertEquals("Mismatched entry port preference",
-                preferredPort, HostConfigEntry.resolvePort(originalPort, preferredPort));
+            preferredPort, HostConfigEntry.resolvePort(originalPort, preferredPort));
 
         for (int entryPort : new int[] {-1, 0}) {
             assertEquals("Non-preferred original port for entry port=" + entryPort,
-                    originalPort, HostConfigEntry.resolvePort(originalPort, entryPort));
+                originalPort, HostConfigEntry.resolvePort(originalPort, entryPort));
         }
     }
 
@@ -211,7 +211,7 @@ public class HostConfigEntryTest extends BaseTestSupport {
 
         for (String entryUser : new String[] {null, ""}) {
             assertSame("Non-preferred original user for entry user='" + entryUser + "'",
-                    originalUser, HostConfigEntry.resolveUsername(originalUser, entryUser));
+                originalUser, HostConfigEntry.resolveUsername(originalUser, entryUser));
         }
     }
 
@@ -281,8 +281,10 @@ public class HostConfigEntryTest extends BaseTestSupport {
         final String hostValue = getCurrentTestName();
         HostConfigEntry expected = new HostConfigEntry(hostValue, hostValue, 7365, hostValue);
         List<HostConfigEntry> matches = new ArrayList<>();
-        matches.add(new HostConfigEntry(HostPatternsHolder.ALL_HOSTS_PATTERN, getClass().getSimpleName(), Short.MAX_VALUE, getClass().getSimpleName()));
-        matches.add(new HostConfigEntry(hostValue + String.valueOf(HostPatternsHolder.WILDCARD_PATTERN), getClass().getSimpleName(), Byte.MAX_VALUE, getClass().getSimpleName()));
+        matches.add(new HostConfigEntry(HostPatternsHolder.ALL_HOSTS_PATTERN,
+            getClass().getSimpleName(), Short.MAX_VALUE, getClass().getSimpleName()));
+        matches.add(new HostConfigEntry(hostValue + Character.toString(HostPatternsHolder.WILDCARD_PATTERN),
+            getClass().getSimpleName(), Byte.MAX_VALUE, getClass().getSimpleName()));
         matches.add(expected);
 
         for (int index = 0; index < matches.size(); index++) {

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/93604f76/sshd-core/src/test/java/org/apache/sshd/client/kex/KexTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/kex/KexTest.java b/sshd-core/src/test/java/org/apache/sshd/client/kex/KexTest.java
index 9fe1aff..6ad17b2 100644
--- a/sshd-core/src/test/java/org/apache/sshd/client/kex/KexTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/client/kex/KexTest.java
@@ -146,7 +146,7 @@ public class KexTest extends BaseTestSupport {
                     for (int i = 0; i < 10; i++) {
                         sb.append("0123456789");
                     }
-                    sb.append("\n");
+                    sb.append('\n');
                     teeOut.write(sb.toString().getBytes(StandardCharsets.UTF_8));
 
                     teeOut.write("exit\n".getBytes(StandardCharsets.UTF_8));

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/93604f76/sshd-core/src/test/java/org/apache/sshd/common/PropertyResolverUtilsTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/PropertyResolverUtilsTest.java b/sshd-core/src/test/java/org/apache/sshd/common/PropertyResolverUtilsTest.java
index 27b96e0..12319c0 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/PropertyResolverUtilsTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/PropertyResolverUtilsTest.java
@@ -131,7 +131,7 @@ public class PropertyResolverUtilsTest extends BaseTestSupport {
         {
             String actual = PropertyResolverUtils.getString(resolver, name);
             assertNotNull("No actual String value found for storage as " + storage, actual);
-            assertEquals("Mismatched values on String retrieval for storage as " + storage, Long.toString(expected), actual.toString());
+            assertEquals("Mismatched values on String retrieval for storage as " + storage, Long.toString(expected), actual);
         }
     }
 
@@ -170,7 +170,7 @@ public class PropertyResolverUtilsTest extends BaseTestSupport {
         {
             String actual = PropertyResolverUtils.getString(resolver, name);
             assertNotNull("No actual String value found for storage as " + storage, actual);
-            assertEquals("Mismatched values on String retrieval for storage as " + storage, Integer.toString(expected), actual.toString());
+            assertEquals("Mismatched values on String retrieval for storage as " + storage, Integer.toString(expected), actual);
         }
     }
 
@@ -206,7 +206,7 @@ public class PropertyResolverUtilsTest extends BaseTestSupport {
         {
             String actual = PropertyResolverUtils.getString(resolver, name);
             assertNotNull("No actual String value found for storage as " + storage, actual);
-            assertEquals("Mismatched values on String retrieval for storage as " + storage, Boolean.toString(expected), actual.toString());
+            assertEquals("Mismatched values on String retrieval for storage as " + storage, Boolean.toString(expected), actual);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/93604f76/sshd-core/src/test/java/org/apache/sshd/common/util/SelectorUtilsTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/util/SelectorUtilsTest.java b/sshd-core/src/test/java/org/apache/sshd/common/util/SelectorUtilsTest.java
index b29452f..e13fa9b 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/util/SelectorUtilsTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/util/SelectorUtilsTest.java
@@ -52,9 +52,9 @@ public class SelectorUtilsTest extends BaseTestSupport {
     private void testApplySlashifyRules(char slash) {
         for (String expected : new String[]{
             null, "", getCurrentTestName(),
-            getClass().getSimpleName() + String.valueOf(slash) + getCurrentTestName(),
-            String.valueOf(slash)  + getClass().getSimpleName(),
-            String.valueOf(slash)  + getClass().getSimpleName() + String.valueOf(slash)  + getCurrentTestName()
+            getClass().getSimpleName() + Character.toString(slash) + getCurrentTestName(),
+            Character.toString(slash)  + getClass().getSimpleName(),
+            Character.toString(slash)  + getClass().getSimpleName() + Character.toString(slash)  + getCurrentTestName()
         }) {
             String actual = SelectorUtils.applySlashifyRules(expected, slash);
             assertSame("Mismatched results for '" + expected + "'", expected, actual);

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/93604f76/sshd-pmd-ruleset.xml
----------------------------------------------------------------------
diff --git a/sshd-pmd-ruleset.xml b/sshd-pmd-ruleset.xml
index 69f45be..57e3f98 100644
--- a/sshd-pmd-ruleset.xml
+++ b/sshd-pmd-ruleset.xml
@@ -1,35 +1,65 @@
-<?xml version="1.0"?> 
-<ruleset name="MINA SSHD PMD ruleset" 
-   xmlns="http://pmd.sourceforge.net/ruleset/2.0.0" 
-   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
-   xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd"> 
+<?xml version="1.0"?>
+<ruleset name="MINA SSHD PMD ruleset"
+   xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
+   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+   xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
 
-   <description> 
-       This ruleset defines the PMD rules for MINA SSHD project 
-   </description> 
+   <description>
+       This ruleset defines the PMD rules for MINA SSHD project
+   </description>
 
-       <!-- See https://pmd.github.io/pmd-6.2.0/pmd_rules_java.html --> 
-   <rule ref="category/java/errorprone.xml/AvoidMultipleUnaryOperators" /> 
-   <rule ref="category/java/errorprone.xml/AvoidUsingOctalValues" /> 
-   <rule ref="category/java/errorprone.xml/MissingSerialVersionUID" /> 
-   <rule ref="category/java/errorprone.xml/BrokenNullCheck" /> 
-   <rule ref="category/java/errorprone.xml/MisplacedNullCheck" /> 
-   <rule ref="category/java/errorprone.xml/OverrideBothEqualsAndHashcode" /> 
-   <rule ref="category/java/errorprone.xml/ReturnFromFinallyBlock" /> 
-   <rule ref="category/java/errorprone.xml/UnconditionalIfStatement" /> 
-   <rule ref="category/java/errorprone.xml/ProperCloneImplementation" /> 
-   <rule ref="category/java/errorprone.xml/CloneMethodMustImplementCloneable" /> 
-   <rule ref="category/java/errorprone.xml/AssignmentInOperand" /> 
+       <!-- See https://pmd.github.io/pmd-6.2.0/pmd_rules_java.html -->
+    <rule ref="category/java/errorprone.xml/AvoidMultipleUnaryOperators" />
+    <rule ref="category/java/errorprone.xml/AvoidUsingOctalValues" />
+    <rule ref="category/java/errorprone.xml/MissingSerialVersionUID" />
+    <rule ref="category/java/errorprone.xml/BrokenNullCheck" />
+    <rule ref="category/java/errorprone.xml/MisplacedNullCheck" />
+    <rule ref="category/java/errorprone.xml/OverrideBothEqualsAndHashcode" />
+    <rule ref="category/java/errorprone.xml/ReturnFromFinallyBlock" />
+    <rule ref="category/java/errorprone.xml/UnconditionalIfStatement" />
+    <rule ref="category/java/errorprone.xml/ProperCloneImplementation" />
+    <rule ref="category/java/errorprone.xml/CloneMethodMustImplementCloneable" />
+    <rule ref="category/java/errorprone.xml/AssignmentInOperand" />
+    <rule ref="category/java/errorprone.xml/BadComparison" />
+    <rule ref="category/java/errorprone.xml/EqualsNull" />
+    <rule ref="category/java/errorprone.xml/NonCaseLabelInSwitchStatement" />
+    <rule ref="category/java/errorprone.xml/AvoidCallingFinalize" />
+    <rule ref="category/java/errorprone.xml/EmptyFinalizer" />
+    <rule ref="category/java/errorprone.xml/FinalizeDoesNotCallSuperFinalize" />
+    <rule ref="category/java/errorprone.xml/FinalizeOnlyCallsSuperFinalize" />
+    <rule ref="category/java/errorprone.xml/FinalizeOverloaded" />
+    <rule ref="category/java/errorprone.xml/FinalizeShouldBeProtected" />
+    <rule ref="category/java/errorprone.xml/UseEqualsToCompareStrings" />
+    <rule ref="category/java/errorprone.xml/UnnecessaryCaseChange" />
+    <rule ref="category/java/errorprone.xml/UnnecessaryConversionTemporary" />
+    <rule ref="category/java/errorprone.xml/UselessOperationOnImmutable" />
 
-   <rule ref="category/java/codestyle.xml/AtLeastOneConstructor" /> 
-   <rule ref="category/java/codestyle.xml/ExtendsObject" />
-   <rule ref="category/java/codestyle.xml/BooleanGetMethodName" />
+    <rule ref="category/java/codestyle.xml/AtLeastOneConstructor" />
+    <rule ref="category/java/codestyle.xml/ExtendsObject" />
+    <rule ref="category/java/codestyle.xml/BooleanGetMethodName" />
+    <rule ref="category/java/codestyle.xml/ForLoopsMustUseBraces" />
+    <rule ref="category/java/codestyle.xml/IfElseStmtsMustUseBraces" />
+    <rule ref="category/java/codestyle.xml/IfStmtsMustUseBraces" />
+    <rule ref="category/java/codestyle.xml/WhileLoopsMustUseBraces" />
 
-   <rule ref="category/java/multithreading.xml/UseNotifyAllInsteadOfNotify" /> 
-   <rule ref="category/java/documentation.xml/UncommentedEmptyMethodBody" />
-   <rule ref="category/java/performance.xml/BooleanInstantiation" /> 
+    <rule ref="category/java/design.xml/AvoidDeeplyNestedIfStmts">
+        <properties>
+            <property name="problemDepth" value="5"/>
+        </properties>
+    </rule>
 
-   <!-- rule ref="category/java/bestpractices.xml/MethodReturnsInternalArray" / -->
-   <rule ref="category/java/bestpractices.xml/AvoidPrintStackTrace" />
-   <rule ref="category/java/bestpractices.xml/MissingOverride" />
-</ruleset>
\ No newline at end of file
+    <rule ref="category/java/multithreading.xml/UseNotifyAllInsteadOfNotify" />
+    <rule ref="category/java/documentation.xml/UncommentedEmptyMethodBody" />
+
+    <rule ref="category/java/performance.xml/BooleanInstantiation" />
+    <rule ref="category/java/performance.xml/AppendCharacterWithChar" />
+    <!-- rule ref="category/java/performance.xml/ConsecutiveLiteralAppends" / -->
+    <rule ref="category/java/performance.xml/StringInstantiation" />
+    <rule ref="category/java/performance.xml/StringToString" />
+    <rule ref="category/java/performance.xml/UseIndexOfChar" />
+    <rule ref="category/java/performance.xml/UselessStringValueOf" />
+
+    <!-- rule ref="category/java/bestpractices.xml/MethodReturnsInternalArray" / -->
+    <rule ref="category/java/bestpractices.xml/AvoidPrintStackTrace" />
+    <rule ref="category/java/bestpractices.xml/MissingOverride" />
+</ruleset>

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/93604f76/sshd-scp/src/main/java/org/apache/sshd/client/scp/ScpClient.java
----------------------------------------------------------------------
diff --git a/sshd-scp/src/main/java/org/apache/sshd/client/scp/ScpClient.java b/sshd-scp/src/main/java/org/apache/sshd/client/scp/ScpClient.java
index b2a6091..0e98e0c 100644
--- a/sshd-scp/src/main/java/org/apache/sshd/client/scp/ScpClient.java
+++ b/sshd-scp/src/main/java/org/apache/sshd/client/scp/ScpClient.java
@@ -154,7 +154,7 @@ public interface ScpClient extends SessionHolder<ClientSession>, ClientSessionHo
             sb.append(" -p");
         }
 
-        sb.append(" -t").append(" --").append(" ").append(remote);
+        sb.append(" -t").append(" --").append(' ').append(remote);
         return sb.toString();
     }
 

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/93604f76/sshd-scp/src/main/java/org/apache/sshd/common/scp/ScpHelper.java
----------------------------------------------------------------------
diff --git a/sshd-scp/src/main/java/org/apache/sshd/common/scp/ScpHelper.java b/sshd-scp/src/main/java/org/apache/sshd/common/scp/ScpHelper.java
index 1cbea2d..48bc57a 100644
--- a/sshd-scp/src/main/java/org/apache/sshd/common/scp/ScpHelper.java
+++ b/sshd-scp/src/main/java/org/apache/sshd/common/scp/ScpHelper.java
@@ -180,20 +180,23 @@ public class ScpHelper extends AbstractLoggingBean implements SessionHolder<Sess
                 case -1:
                     return;
                 case 'D':
+                    line = readLine();
+                    line = Character.toString((char) c) + line;
                     isDir = true;
-                    line = String.valueOf((char) c) + readLine();
                     if (log.isDebugEnabled()) {
                         log.debug("receive({}) - Received 'D' header: {}", this, line);
                     }
                     break;
                 case 'C':
-                    line = String.valueOf((char) c) + readLine();
+                    line = readLine();
+                    line = Character.toString((char) c) + line;
                     if (log.isDebugEnabled()) {
                         log.debug("receive({}) - Received 'C' header: {}", this, line);
                     }
                     break;
                 case 'T':
-                    line = String.valueOf((char) c) + readLine();
+                    line = readLine();
+                    line = Character.toString((char) c) + line;
                     if (log.isDebugEnabled()) {
                         log.debug("receive({}) - Received 'T' header: {}", this, line);
                     }
@@ -201,7 +204,8 @@ public class ScpHelper extends AbstractLoggingBean implements SessionHolder<Sess
                     ack();
                     continue;
                 case 'E':
-                    line = String.valueOf((char) c) + readLine();
+                    line = readLine();
+                    line = Character.toString((char) c) + line;
                     if (log.isDebugEnabled()) {
                         log.debug("receive({}) - Received 'E' header: {}", this, line);
                     }

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/93604f76/sshd-scp/src/main/java/org/apache/sshd/common/scp/ScpLocation.java
----------------------------------------------------------------------
diff --git a/sshd-scp/src/main/java/org/apache/sshd/common/scp/ScpLocation.java b/sshd-scp/src/main/java/org/apache/sshd/common/scp/ScpLocation.java
index d2a9afc..c85ef54 100644
--- a/sshd-scp/src/main/java/org/apache/sshd/common/scp/ScpLocation.java
+++ b/sshd-scp/src/main/java/org/apache/sshd/common/scp/ScpLocation.java
@@ -156,8 +156,11 @@ public class ScpLocation implements MutableUserHolder, Serializable, Cloneable {
             return p;
         }
 
-        return resolveUsername() + String.valueOf(USERNAME_PART_SEPARATOR)
-             + getHost() + String.valueOf(HOST_PART_SEPARATOR) + p;
+        return resolveUsername()
+            + Character.toString(USERNAME_PART_SEPARATOR)
+            + getHost()
+            + Character.toString(HOST_PART_SEPARATOR)
+            + p;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/93604f76/sshd-sftp/src/main/java/org/apache/sshd/client/subsystem/sftp/SftpFileSystem.java
----------------------------------------------------------------------
diff --git a/sshd-sftp/src/main/java/org/apache/sshd/client/subsystem/sftp/SftpFileSystem.java b/sshd-sftp/src/main/java/org/apache/sshd/client/subsystem/sftp/SftpFileSystem.java
index 0ea8cd7..9074a45 100644
--- a/sshd-sftp/src/main/java/org/apache/sshd/client/subsystem/sftp/SftpFileSystem.java
+++ b/sshd-sftp/src/main/java/org/apache/sshd/client/subsystem/sftp/SftpFileSystem.java
@@ -208,7 +208,7 @@ public class SftpFileSystem extends BaseFileSystem<SftpPath> implements ClientSe
 
     @Override
     public String toString() {
-        return getClass().getSimpleName() + "[" + String.valueOf(getClientSession()) + "]";
+        return getClass().getSimpleName() + "[" + getClientSession() + "]";
     }
 
     private final class Wrapper extends AbstractSftpClient {