[SSHD-724] Fixed most of the static checker reported issues
Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/f9b97607 Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/f9b97607 Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/f9b97607 Branch: refs/heads/master Commit: f9b9760734936de7640d91cce57bdc266eadd3a6 Parents: 385f21d Author: Lyor Goldstein <lyor.goldst...@gmail.com> Authored: Mon Dec 26 20:15:12 2016 +0200 Committer: Lyor Goldstein <lyor.goldst...@gmail.com> Committed: Mon Dec 26 20:29:39 2016 +0200 ---------------------------------------------------------------------- .../java/org/apache/sshd/client/SshClient.java | 4 +++- .../auth/AuthenticationIdentitiesProvider.java | 2 +- .../sshd/client/channel/ChannelDirectTcpip.java | 2 +- .../sshd/client/scp/DefaultScpClient.java | 4 +++- .../org/apache/sshd/common/channel/PtyMode.java | 2 +- .../apache/sshd/common/channel/SttySupport.java | 9 +++++---- .../apache/sshd/common/forward/SocksProxy.java | 2 +- .../common/keyprovider/KeyPairProvider.java | 2 +- .../apache/sshd/common/util/buffer/Buffer.java | 2 +- .../sshd/server/auth/gss/UserAuthGSS.java | 9 +-------- .../java/org/apache/sshd/server/kex/Moduli.java | 9 +++++++-- .../java/org/apache/sshd/KeyReExchangeTest.java | 20 ++++++++++---------- .../test/java/org/apache/sshd/ProxyTest.java | 2 +- .../sshd/client/channel/ChannelExecMain.java | 4 +++- .../org/apache/sshd/client/scp/ScpTest.java | 4 ++-- .../subsystem/sftp/SftpFileSystemTest.java | 2 +- .../apache/sshd/common/channel/WindowTest.java | 11 ++++++----- .../apache/sshd/common/cipher/CipherTest.java | 3 ++- .../sshd/common/file/util/BasePathTest.java | 2 +- .../sshd/common/forward/PortForwardingTest.java | 10 +++++----- .../sshd/common/util/SttySupportTest.java | 5 +++-- .../sshd/util/test/AsyncEchoShellFactory.java | 2 +- 22 files changed, 60 insertions(+), 52 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/f9b97607/sshd-core/src/main/java/org/apache/sshd/client/SshClient.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/client/SshClient.java b/sshd-core/src/main/java/org/apache/sshd/client/SshClient.java index 16f9d91..63755d2 100644 --- a/sshd-core/src/main/java/org/apache/sshd/client/SshClient.java +++ b/sshd-core/src/main/java/org/apache/sshd/client/SshClient.java @@ -30,6 +30,7 @@ import java.io.StringWriter; import java.net.InetSocketAddress; import java.net.SocketAddress; import java.net.SocketTimeoutException; +import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.LinkOption; import java.nio.file.Path; @@ -1377,7 +1378,8 @@ public class SshClient extends AbstractFactoryManager implements ClientFactoryMa } ClientSession session = null; - try (BufferedReader stdin = new BufferedReader(new InputStreamReader(new NoCloseInputStream(System.in)))) { + try (BufferedReader stdin = new BufferedReader( + new InputStreamReader(new NoCloseInputStream(System.in), Charset.defaultCharset()))) { if (!error) { setupLogging(level, stdout, stderr, logStream); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/f9b97607/sshd-core/src/main/java/org/apache/sshd/client/auth/AuthenticationIdentitiesProvider.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/client/auth/AuthenticationIdentitiesProvider.java b/sshd-core/src/main/java/org/apache/sshd/client/auth/AuthenticationIdentitiesProvider.java index 9bac5c3..8bc175b 100644 --- a/sshd-core/src/main/java/org/apache/sshd/client/auth/AuthenticationIdentitiesProvider.java +++ b/sshd-core/src/main/java/org/apache/sshd/client/auth/AuthenticationIdentitiesProvider.java @@ -83,7 +83,7 @@ public interface AuthenticationIdentitiesProvider extends KeyIdentityProvider, P * @param identities The {@link Iterable} identities - OK if {@code null}/empty * @return An {@link AuthenticationIdentitiesProvider} wrapping the identities */ - static AuthenticationIdentitiesProvider wrap(final Iterable<?> identities) { + static AuthenticationIdentitiesProvider wrap(Iterable<?> identities) { return new AuthenticationIdentitiesProvider() { @Override public Iterable<KeyPair> loadKeys() { http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/f9b97607/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelDirectTcpip.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelDirectTcpip.java b/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelDirectTcpip.java index 0a077c2..5658e95 100644 --- a/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelDirectTcpip.java +++ b/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelDirectTcpip.java @@ -65,7 +65,7 @@ public class ChannelDirectTcpip extends AbstractClientChannel { } @Override - public OpenFuture open() throws IOException { + public synchronized OpenFuture open() throws IOException { if (closeFuture.isClosed()) { throw new SshException("Session has been closed"); } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/f9b97607/sshd-core/src/main/java/org/apache/sshd/client/scp/DefaultScpClient.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/client/scp/DefaultScpClient.java b/sshd-core/src/main/java/org/apache/sshd/client/scp/DefaultScpClient.java index 74d598e..c06210f 100644 --- a/sshd-core/src/main/java/org/apache/sshd/client/scp/DefaultScpClient.java +++ b/sshd-core/src/main/java/org/apache/sshd/client/scp/DefaultScpClient.java @@ -24,6 +24,7 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintStream; +import java.nio.charset.Charset; import java.nio.file.FileSystem; import java.nio.file.Path; import java.nio.file.attribute.PosixFilePermission; @@ -240,7 +241,8 @@ public class DefaultScpClient extends AbstractScpClient { final PrintStream stdout = System.out; final PrintStream stderr = System.err; OutputStream logStream = stdout; - try (BufferedReader stdin = new BufferedReader(new InputStreamReader(new NoCloseInputStream(System.in)))) { + try (BufferedReader stdin = new BufferedReader( + new InputStreamReader(new NoCloseInputStream(System.in), Charset.defaultCharset()))) { args = normalizeCommandArguments(stdout, stderr, args); int numArgs = GenericUtils.length(args); // see the way normalizeCommandArguments works... http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/f9b97607/sshd-core/src/main/java/org/apache/sshd/common/channel/PtyMode.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/common/channel/PtyMode.java b/sshd-core/src/main/java/org/apache/sshd/common/channel/PtyMode.java index f8c01c7..f58f4cc 100644 --- a/sshd-core/src/main/java/org/apache/sshd/common/channel/PtyMode.java +++ b/sshd-core/src/main/java/org/apache/sshd/common/channel/PtyMode.java @@ -297,7 +297,7 @@ public enum PtyMode { Collections.unmodifiableMap( GenericUtils.toSortedMap(MODES, PtyMode::toInt, Function.identity(), Comparator.naturalOrder())); - private int v; + private final int v; PtyMode(int v) { this.v = v; http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/f9b97607/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 650fe55..11676e2 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 @@ -22,6 +22,7 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.nio.charset.Charset; import java.util.Map; import java.util.StringTokenizer; import java.util.TreeMap; @@ -89,8 +90,8 @@ public final class SttySupport { if (idx1 < 0) { return -1; } - if (idx1 > 0 && Character.isLetterOrDigit(stty.charAt(idx1 - 1)) - || (idx2 < stty.length() && Character.isLetterOrDigit(stty.charAt(idx2)))) { + if ((idx1 > 0) && Character.isLetterOrDigit(stty.charAt(idx1 - 1)) + || ((idx2 < stty.length()) && Character.isLetterOrDigit(stty.charAt(idx2)))) { cur = idx2; continue; } @@ -257,7 +258,7 @@ public final class SttySupport { * @throws IOException If failed to execute the command * @throws InterruptedException If interrupted while awaiting command execution */ - private static String exec(final String ... cmd) + private static String exec(String ... cmd) throws IOException, InterruptedException { try (ByteArrayOutputStream bout = new ByteArrayOutputStream()) { Process p = Runtime.getRuntime().exec(cmd); @@ -265,7 +266,7 @@ public final class SttySupport { copyStream(p.getErrorStream(), bout); p.waitFor(); - String result = new String(bout.toByteArray()); + String result = new String(bout.toByteArray(), Charset.defaultCharset()); return result; } } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/f9b97607/sshd-core/src/main/java/org/apache/sshd/common/forward/SocksProxy.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/common/forward/SocksProxy.java b/sshd-core/src/main/java/org/apache/sshd/common/forward/SocksProxy.java index 5e38e01..e12b0bb 100644 --- a/sshd-core/src/main/java/org/apache/sshd/common/forward/SocksProxy.java +++ b/sshd-core/src/main/java/org/apache/sshd/common/forward/SocksProxy.java @@ -90,7 +90,7 @@ public class SocksProxy extends AbstractCloseable implements IoHandler { session.close(false); } - public abstract class Proxy implements Closeable { + public abstract static class Proxy implements Closeable { IoSession session; TcpipClientChannel channel; http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/f9b97607/sshd-core/src/main/java/org/apache/sshd/common/keyprovider/KeyPairProvider.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/common/keyprovider/KeyPairProvider.java b/sshd-core/src/main/java/org/apache/sshd/common/keyprovider/KeyPairProvider.java index 4634589..e7d2b7d 100644 --- a/sshd-core/src/main/java/org/apache/sshd/common/keyprovider/KeyPairProvider.java +++ b/sshd-core/src/main/java/org/apache/sshd/common/keyprovider/KeyPairProvider.java @@ -140,7 +140,7 @@ public interface KeyPairProvider extends KeyIdentityProvider { * returns {@link #EMPTY_KEYPAIR_PROVIDER}) * @return The provider wrapper */ - static KeyPairProvider wrap(final Iterable<KeyPair> pairs) { + static KeyPairProvider wrap(Iterable<KeyPair> pairs) { return (pairs == null) ? EMPTY_KEYPAIR_PROVIDER : new KeyPairProvider() { @Override public Iterable<KeyPair> loadKeys() { http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/f9b97607/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/Buffer.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/Buffer.java b/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/Buffer.java index 44c9b05..74c1491 100644 --- a/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/Buffer.java +++ b/sshd-core/src/main/java/org/apache/sshd/common/util/buffer/Buffer.java @@ -210,7 +210,7 @@ public abstract class Buffer implements Readable { ensureAvailable(Short.BYTES); getRawBytes(workBuf, 0, Short.BYTES); short v = (short) ((workBuf[1] << Byte.SIZE) & 0xFF00); - v |= workBuf[0] & 0xF; + v |= (short) (workBuf[0] & 0xF); return v; } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/f9b97607/sshd-core/src/main/java/org/apache/sshd/server/auth/gss/UserAuthGSS.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/auth/gss/UserAuthGSS.java b/sshd-core/src/main/java/org/apache/sshd/server/auth/gss/UserAuthGSS.java index 1b43e51..0ef8782 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/auth/gss/UserAuthGSS.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/auth/gss/UserAuthGSS.java @@ -108,7 +108,7 @@ public class UserAuthGSS extends AbstractUserAuth { } else { int msg = buffer.getUByte(); if (!((msg == SshConstants.SSH_MSG_USERAUTH_INFO_RESPONSE) - || (msg == SshConstants.SSH_MSG_USERAUTH_GSSAPI_MIC) && context.isEstablished())) { + || ((msg == SshConstants.SSH_MSG_USERAUTH_GSSAPI_MIC)) && context.isEstablished())) { throw new SshException(SshConstants.SSH2_DISCONNECT_PROTOCOL_ERROR, "Packet not supported by user authentication method: " + SshConstants.getCommandMessageName(msg)); } @@ -120,7 +120,6 @@ public class UserAuthGSS extends AbstractUserAuth { // If the context is established, this must be a MIC message if (context.isEstablished()) { - if (msg != SshConstants.SSH_MSG_USERAUTH_GSSAPI_MIC) { return Boolean.FALSE; } @@ -128,7 +127,6 @@ public class UserAuthGSS extends AbstractUserAuth { // Make the MIC message so the token can be verified Buffer msgbuf = new ByteArrayBuffer(); - msgbuf.putBytes(ValidateUtils.checkNotNullAndNotEmpty(session.getSessionId(), "No current session ID")); msgbuf.putByte(SshConstants.SSH_MSG_USERAUTH_REQUEST); msgbuf.putString(super.getUsername()); @@ -137,7 +135,6 @@ public class UserAuthGSS extends AbstractUserAuth { byte[] msgbytes = msgbuf.getCompactData(); byte[] inmic = buffer.getBytes(); - try { context.verifyMIC(inmic, 0, inmic.length, msgbytes, 0, msgbytes.length, new MessageProp(false)); if (log.isDebugEnabled()) { @@ -152,15 +149,12 @@ public class UserAuthGSS extends AbstractUserAuth { return Boolean.FALSE; } } else { - // Not established - new token to process - byte[] tok = buffer.getBytes(); byte[] out = context.acceptSecContext(tok, 0, tok.length); boolean established = context.isEstablished(); // Validate identity if context is now established - if (established && (identity == null)) { identity = context.getSrcName().toString(); if (log.isDebugEnabled()) { @@ -173,7 +167,6 @@ public class UserAuthGSS extends AbstractUserAuth { } // Send return token if necessary - if (NumberUtils.length(out) > 0) { Buffer b = session.createBuffer(SshConstants.SSH_MSG_USERAUTH_INFO_RESPONSE, out.length + Integer.SIZE); b.putBytes(out); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/f9b97607/sshd-core/src/main/java/org/apache/sshd/server/kex/Moduli.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/kex/Moduli.java b/sshd-core/src/main/java/org/apache/sshd/server/kex/Moduli.java index 2a30525..edc08d7 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/kex/Moduli.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/kex/Moduli.java @@ -23,6 +23,7 @@ import java.io.IOException; import java.io.InputStreamReader; import java.math.BigInteger; import java.net.URL; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; @@ -48,33 +49,38 @@ public final class Moduli { public static List<DhGroup> parseModuli(URL url) throws IOException { List<DhGroup> groups = new ArrayList<>(); - try (BufferedReader r = new BufferedReader(new InputStreamReader(url.openStream()))) { + try (BufferedReader r = new BufferedReader(new InputStreamReader(url.openStream(), StandardCharsets.UTF_8))) { String line; while ((line = r.readLine()) != null) { line = line.trim(); if (line.startsWith("#")) { continue; } + String[] parts = line.split("\\s+"); // Ensure valid line if (parts.length != 7) { continue; } + // Discard moduli types which are not safe int type = Integer.parseInt(parts[1]); if (type != MODULI_TYPE_SAFE) { continue; } + // Discard untested modulis int tests = Integer.parseInt(parts[2]); if ((tests & MODULI_TESTS_COMPOSITE) != 0 || (tests & ~MODULI_TESTS_COMPOSITE) == 0) { continue; } + // Discard untried int tries = Integer.parseInt(parts[3]); if (tries == 0) { continue; } + DhGroup group = new DhGroup(); group.size = Integer.parseInt(parts[4]) + 1; group.g = new BigInteger(parts[5], 16); @@ -84,5 +90,4 @@ public final class Moduli { return groups; } } - } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/f9b97607/sshd-core/src/test/java/org/apache/sshd/KeyReExchangeTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/KeyReExchangeTest.java b/sshd-core/src/test/java/org/apache/sshd/KeyReExchangeTest.java index 2f0e01d..06c9c75 100644 --- a/sshd-core/src/test/java/org/apache/sshd/KeyReExchangeTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/KeyReExchangeTest.java @@ -229,7 +229,7 @@ public class KeyReExchangeTest extends BaseTestSupport { os.flush(); int len = is.read(data); - String str = new String(data, 0, len); + String str = new String(data, 0, len, StandardCharsets.UTF_8); assertEquals("Mismatched data at iteration " + i, expected, str); outputDebugMessage("Request re-key #%d", i); @@ -264,14 +264,14 @@ public class KeyReExchangeTest extends BaseTestSupport { private long writeCount; @Override - public void write(int b) { + public synchronized void write(int b) { super.write(b); updateWriteCount(1L); pipedCount.release(1); } @Override - public void write(byte[] b, int off, int len) { + public synchronized void write(byte[] b, int off, int len) { super.write(b, off, len); updateWriteCount(len); pipedCount.release(len); @@ -342,14 +342,14 @@ public class KeyReExchangeTest extends BaseTestSupport { private long writeCount; @Override - public void write(int b) { + public synchronized void write(int b) { super.write(b); updateWriteCount(1L); pipedCount.release(1); } @Override - public void write(byte[] b, int off, int len) { + public synchronized void write(byte[] b, int off, int len) { super.write(b, off, len); updateWriteCount(len); pipedCount.release(len); @@ -444,14 +444,14 @@ public class KeyReExchangeTest extends BaseTestSupport { private long writeCount; @Override - public void write(int b) { + public synchronized void write(int b) { super.write(b); updateWriteCount(1L); pipedCount.release(1); } @Override - public void write(byte[] b, int off, int len) { + public synchronized void write(byte[] b, int off, int len) { super.write(b, off, len); updateWriteCount(len); pipedCount.release(len); @@ -480,7 +480,7 @@ public class KeyReExchangeTest extends BaseTestSupport { teeOut.write("this is my command\n".getBytes(StandardCharsets.UTF_8)); teeOut.flush(); - final AtomicInteger exchanges = new AtomicInteger(); + AtomicInteger exchanges = new AtomicInteger(); session.addSessionListener(new SessionListener() { @Override public void sessionEvent(Session session, Event event) { @@ -558,14 +558,14 @@ public class KeyReExchangeTest extends BaseTestSupport { private long writeCount; @Override - public void write(int b) { + public synchronized void write(int b) { super.write(b); updateWriteCount(1L); pipedCount.release(1); } @Override - public void write(byte[] b, int off, int len) { + public synchronized void write(byte[] b, int off, int len) { super.write(b, off, len); updateWriteCount(len); pipedCount.release(len); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/f9b97607/sshd-core/src/test/java/org/apache/sshd/ProxyTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/ProxyTest.java b/sshd-core/src/test/java/org/apache/sshd/ProxyTest.java index d5ced50..285b7c1 100644 --- a/sshd-core/src/test/java/org/apache/sshd/ProxyTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/ProxyTest.java @@ -257,7 +257,7 @@ public class ProxyTest extends BaseTestSupport { sockOut.flush(); int l = sockIn.read(buf); - assertEquals("Mismatched data at iteration " + i, expected, new String(buf, 0, l)); + assertEquals("Mismatched data at iteration " + i, expected, new String(buf, 0, l, StandardCharsets.UTF_8)); } } } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/f9b97607/sshd-core/src/test/java/org/apache/sshd/client/channel/ChannelExecMain.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/client/channel/ChannelExecMain.java b/sshd-core/src/test/java/org/apache/sshd/client/channel/ChannelExecMain.java index 495459a..798fe70 100644 --- a/sshd-core/src/test/java/org/apache/sshd/client/channel/ChannelExecMain.java +++ b/sshd-core/src/test/java/org/apache/sshd/client/channel/ChannelExecMain.java @@ -22,6 +22,7 @@ package org.apache.sshd.client.channel; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintStream; +import java.nio.charset.Charset; import org.apache.sshd.client.SshClient; import org.apache.sshd.client.session.ClientSession; @@ -69,7 +70,8 @@ public class ChannelExecMain extends BaseTestSupport { public static void main(String[] args) throws Exception { PrintStream stdout = System.out; PrintStream stderr = System.err; - try (BufferedReader stdin = new BufferedReader(new InputStreamReader(new NoCloseInputStream(System.in)))) { + try (BufferedReader stdin = new BufferedReader( + new InputStreamReader(new NoCloseInputStream(System.in), Charset.defaultCharset()))) { ClientSession session = SshClient.setupClientSession("-P", stdin, stdout, stderr, args); if (session == null) { System.err.println("usage: channelExec [-i identity] [-l login] [-P port] [-o option=value]" http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/f9b97607/sshd-core/src/test/java/org/apache/sshd/client/scp/ScpTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/client/scp/ScpTest.java b/sshd-core/src/test/java/org/apache/sshd/client/scp/ScpTest.java index 66f17b3..bbe1166 100644 --- a/sshd-core/src/test/java/org/apache/sshd/client/scp/ScpTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/client/scp/ScpTest.java @@ -1016,7 +1016,7 @@ public class ScpTest extends BaseTestSupport { os.write(0); os.flush(); - return new String(buffer); + return new String(buffer, StandardCharsets.UTF_8); } finally { c.disconnect(); } @@ -1056,7 +1056,7 @@ public class ScpTest extends BaseTestSupport { os.write(0); os.flush(); - return new String(buffer); + return new String(buffer, StandardCharsets.UTF_8); } finally { c.disconnect(); } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/f9b97607/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpFileSystemTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpFileSystemTest.java b/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpFileSystemTest.java index 8573c46..5590bea 100644 --- a/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpFileSystemTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpFileSystemTest.java @@ -454,7 +454,7 @@ public class SftpFileSystemTest extends BaseTestSupport { attrs = Files.readAttributes(file1, "*", LinkOption.NOFOLLOW_LINKS); outputDebugMessage("%s no-follow attributes: %s", file1, attrs); - assertEquals("Mismatched symlink data", expected, new String(Files.readAllBytes(file1))); + assertEquals("Mismatched symlink data", expected, new String(Files.readAllBytes(file1), StandardCharsets.UTF_8)); try (FileChannel channel = FileChannel.open(file1)) { try (FileLock lock = channel.lock()) { http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/f9b97607/sshd-core/src/test/java/org/apache/sshd/common/channel/WindowTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/channel/WindowTest.java b/sshd-core/src/test/java/org/apache/sshd/common/channel/WindowTest.java index 40cd588..c06f3c3 100644 --- a/sshd-core/src/test/java/org/apache/sshd/common/channel/WindowTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/common/channel/WindowTest.java @@ -168,8 +168,8 @@ public class WindowTest extends BaseTestSupport { final String message = "0123456789"; final int nbMessages = 500; - try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(channel.getInvertedIn())); - BufferedReader reader = new BufferedReader(new InputStreamReader(channel.getInvertedOut()))) { + try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(channel.getInvertedIn(), StandardCharsets.UTF_8)); + BufferedReader reader = new BufferedReader(new InputStreamReader(channel.getInvertedOut(), StandardCharsets.UTF_8))) { for (int i = 0; i < nbMessages; i++) { writer.write(message); @@ -223,8 +223,8 @@ public class WindowTest extends BaseTestSupport { final String message = "0123456789"; final int nbMessages = 500; - try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(inPos)); - BufferedReader reader = new BufferedReader(new InputStreamReader(outPis))) { + try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(inPos, StandardCharsets.UTF_8)); + BufferedReader reader = new BufferedReader(new InputStreamReader(outPis, StandardCharsets.UTF_8))) { for (int i = 0; i < nbMessages; i++) { writer.write(message); writer.write('\n'); @@ -283,7 +283,8 @@ public class WindowTest extends BaseTestSupport { IoReadFuture future = input.read(buf); future.verify(5L, TimeUnit.SECONDS); assertEquals("Mismatched available data at line #" + i, message.length(), buf.available()); - assertEquals("Mismatched data at line #" + i, message, new String(buf.array(), buf.rpos(), buf.available())); + assertEquals("Mismatched data at line #" + i, message, + new String(buf.array(), buf.rpos(), buf.available(), StandardCharsets.UTF_8)); waitForWindowEquals(clientLocal, serverRemote, "client local", "server remote", TimeUnit.SECONDS.toMillis(3L)); waitForWindowEquals(clientRemote, serverLocal, "client remote", "server local", TimeUnit.SECONDS.toMillis(3L)); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/f9b97607/sshd-core/src/test/java/org/apache/sshd/common/cipher/CipherTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/cipher/CipherTest.java b/sshd-core/src/test/java/org/apache/sshd/common/cipher/CipherTest.java index c4b5701..92828cc 100644 --- a/sshd-core/src/test/java/org/apache/sshd/common/cipher/CipherTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/common/cipher/CipherTest.java @@ -29,6 +29,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; import com.jcraft.jsch.JSch; + import org.apache.sshd.common.NamedFactory; import org.apache.sshd.common.NamedResource; import org.apache.sshd.common.channel.Channel; @@ -148,7 +149,7 @@ public class CipherTest extends BaseTestSupport { os.flush(); int len = is.read(actData); - String actual = new String(actData, 0, len); + String actual = new String(actData, 0, len, StandardCharsets.UTF_8); assertEquals("Mismatched command at iteration " + i, expected, actual); } } finally { http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/f9b97607/sshd-core/src/test/java/org/apache/sshd/common/file/util/BasePathTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/file/util/BasePathTest.java b/sshd-core/src/test/java/org/apache/sshd/common/file/util/BasePathTest.java index ee98a22..78a740e 100644 --- a/sshd-core/src/test/java/org/apache/sshd/common/file/util/BasePathTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/common/file/util/BasePathTest.java @@ -463,7 +463,7 @@ public class BasePathTest extends BaseTestSupport { private void testParents(Path path) { Path parent = path.getParent(); - if (root != null && names.size() >= 1 || names.size() > 1) { + if (((root != null) && (names.size() >= 1)) || (names.size() > 1)) { assertNotNull(parent); } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/f9b97607/sshd-core/src/test/java/org/apache/sshd/common/forward/PortForwardingTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/forward/PortForwardingTest.java b/sshd-core/src/test/java/org/apache/sshd/common/forward/PortForwardingTest.java index e3aa2a6..0e23bf9 100644 --- a/sshd-core/src/test/java/org/apache/sshd/common/forward/PortForwardingTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/common/forward/PortForwardingTest.java @@ -438,7 +438,7 @@ public class PortForwardingTest extends BaseTestSupport { output.flush(); int n = input.read(buf); - String res = new String(buf, 0, n); + String res = new String(buf, 0, n, StandardCharsets.UTF_8); assertEquals("Mismatched data at iteration #" + i, expected, res); } } finally { @@ -475,7 +475,7 @@ public class PortForwardingTest extends BaseTestSupport { byte[] buf = new byte[bytes.length + Long.SIZE]; int n = input.read(buf); - String res = new String(buf, 0, n); + String res = new String(buf, 0, n, StandardCharsets.UTF_8); assertEquals("Mismatched data", expected, res); } finally { session.delPortForwardingL(forwardedPort); @@ -575,7 +575,7 @@ public class PortForwardingTest extends BaseTestSupport { byte[] buf = new byte[bytes.length + Long.SIZE]; int n = input.read(buf); - String res = new String(buf, 0, n); + String res = new String(buf, 0, n, StandardCharsets.UTF_8); assertEquals("Mismatched data", expected, res); } finally { tracker.close(); @@ -625,7 +625,7 @@ public class PortForwardingTest extends BaseTestSupport { output.flush(); int n = input.read(buf); - String res = new String(buf, 0, n); + String res = new String(buf, 0, n, StandardCharsets.UTF_8); assertEquals("Mismatched data at iteration #" + i, expected, res); } } finally { @@ -653,7 +653,7 @@ public class PortForwardingTest extends BaseTestSupport { byte[] buf = new byte[bytes.length + Long.SIZE]; int n = input.read(buf); - String res = new String(buf, 0, n); + String res = new String(buf, 0, n, StandardCharsets.UTF_8); assertEquals("Mismatched data", expected, res); } channel.close(false); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/f9b97607/sshd-core/src/test/java/org/apache/sshd/common/util/SttySupportTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/util/SttySupportTest.java b/sshd-core/src/test/java/org/apache/sshd/common/util/SttySupportTest.java index 71ee149..47da098 100644 --- a/sshd-core/src/test/java/org/apache/sshd/common/util/SttySupportTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/common/util/SttySupportTest.java @@ -20,6 +20,7 @@ package org.apache.sshd.common.util; import java.io.InputStreamReader; import java.io.Reader; +import java.nio.charset.StandardCharsets; import java.util.Map; import org.apache.sshd.common.channel.PtyMode; @@ -39,7 +40,7 @@ public class SttySupportTest extends BaseTestSupport { @Test public void parseOutput1() throws Exception { - Reader r = new InputStreamReader(getClass().getResourceAsStream("stty-output-1.txt")); + Reader r = new InputStreamReader(getClass().getResourceAsStream("stty-output-1.txt"), StandardCharsets.UTF_8); char[] buf = new char[8192]; int len = r.read(buf); String stty = new String(buf, 0, len); @@ -49,7 +50,7 @@ public class SttySupportTest extends BaseTestSupport { @Test public void parseOutput2() throws Exception { - Reader r = new InputStreamReader(getClass().getResourceAsStream("stty-output-2.txt")); + Reader r = new InputStreamReader(getClass().getResourceAsStream("stty-output-2.txt"), StandardCharsets.UTF_8); char[] buf = new char[8192]; int len = r.read(buf); String stty = new String(buf, 0, len); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/f9b97607/sshd-core/src/test/java/org/apache/sshd/util/test/AsyncEchoShellFactory.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/util/test/AsyncEchoShellFactory.java b/sshd-core/src/test/java/org/apache/sshd/util/test/AsyncEchoShellFactory.java index 8867f2e..3c8fc83 100644 --- a/sshd-core/src/test/java/org/apache/sshd/util/test/AsyncEchoShellFactory.java +++ b/sshd-core/src/test/java/org/apache/sshd/util/test/AsyncEchoShellFactory.java @@ -129,7 +129,7 @@ public class AsyncEchoShellFactory implements Factory<Command> { @Override public int data(final ChannelSession channel, byte[] buf, int start, int len) throws IOException { - buffer.append(new String(buf, start, len)); + buffer.append(new String(buf, start, len, StandardCharsets.UTF_8)); for (int i = 0; i < buffer.length(); i++) { if (buffer.charAt(i) == '\n') { final String s = buffer.substring(0, i + 1);