Skip to content

Commit 49a450f

Browse files
committed
Fixed some codacy issues
1 parent 80d93ae commit 49a450f

File tree

7 files changed

+32
-26
lines changed

7 files changed

+32
-26
lines changed

examples/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
<dependency>
5656
<groupId>com.hierynomus</groupId>
5757
<artifactId>sshj</artifactId>
58-
<version>0.19.0</version>
58+
<version>0.24.0</version>
5959
</dependency>
6060
</dependencies>
6161

examples/src/main/java/net/schmizz/sshj/examples/Exec.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,32 @@
55
import net.schmizz.sshj.connection.channel.direct.Session;
66
import net.schmizz.sshj.connection.channel.direct.Session.Command;
77

8+
import java.io.Console;
89
import java.io.IOException;
910
import java.util.concurrent.TimeUnit;
1011

1112
/** This examples demonstrates how a remote command can be executed. */
1213
public class Exec {
14+
private static final Console con = System.console();
1315

1416
public static void main(String... args)
1517
throws IOException {
1618
final SSHClient ssh = new SSHClient();
1719
ssh.loadKnownHosts();
18-
1920
ssh.connect("localhost");
21+
Session session = null;
2022
try {
2123
ssh.authPublickey(System.getProperty("user.name"));
22-
final Session session = ssh.startSession();
24+
session = ssh.startSession();
2325
final Command cmd = session.exec("ping -c 1 google.com");
24-
System.out.println(IOUtils.readFully(cmd.getInputStream()).toString());
26+
con.writer().print(IOUtils.readFully(cmd.getInputStream()).toString());
2527
cmd.join(5, TimeUnit.SECONDS);
26-
System.out.println("\n** exit status: " + cmd.getExitStatus());
28+
con.writer().print("\n** exit status: " + cmd.getExitStatus());
2729
} finally {
2830
try {
29-
session.close();
31+
if (session != null) {
32+
session.close();
33+
}
3034
} catch (IOException e) {
3135
// Do Nothing
3236
}

src/main/java/net/schmizz/sshj/common/Buffer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ public void ensureCapacity(int capacity) {
147147

148148
/** Compact this {@link SSHPacket} */
149149
public void compact() {
150-
System.err.println("COMPACTING");
151150
if (available() > 0)
152151
System.arraycopy(data, rpos, data, 0, wpos - rpos);
153152
wpos -= rpos;
@@ -356,8 +355,9 @@ public BigInteger readUInt64AsBigInteger()
356355
}
357356

358357
public T putUInt64(long uint64) {
359-
if (uint64 < 0)
358+
if (uint64 < 0) {
360359
throw new IllegalArgumentException("Invalid value: " + uint64);
360+
}
361361
return putUInt64Unchecked(uint64);
362362
}
363363

src/main/java/net/schmizz/sshj/transport/Reader.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,8 @@ public void run() {
6060
}
6161
}
6262
} catch (Exception e) {
63-
//noinspection StatementWithEmptyBody
64-
if (isInterrupted()) {
65-
// We are meant to shut up and draw to a close if interrupted
66-
} else {
63+
// We are meant to shut up and draw to a close if interrupted
64+
if (!isInterrupted()) {
6765
trans.die(e);
6866
}
6967
}

src/test/java/com/hierynomus/sshj/sftp/RemoteFileTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,7 @@ public void shouldNotGoOutOfBoundsInReadAheadInputStream() throws IOException {
7171
n += rs.read(test, n, 3072 - n);
7272
}
7373

74-
if (test[3072] != 0) {
75-
System.err.println("buffer overrun!");
76-
}
74+
assertThat("buffer overrun", test[3072] == 0);
7775

7876
n += rs.read(test, n, test.length - n); // --> ArrayIndexOutOfBoundsException
7977

src/test/java/net/schmizz/sshj/LoadsOfConnects.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,28 @@
2222

2323
import java.io.IOException;
2424

25+
import static org.junit.Assert.fail;
26+
2527
public class LoadsOfConnects {
2628

2729
protected final Logger log = LoggerFactory.getLogger(getClass());
2830

2931
private final SshFixture fixture = new SshFixture();
3032

3133
@Test
32-
public void loadsOfConnects()
33-
throws IOException, InterruptedException {
34-
for (int i = 0; i < 1000; i++) {
35-
System.out.println("Try " + i);
36-
fixture.start();
37-
fixture.setupConnectedDefaultClient();
38-
fixture.stopClient();
39-
fixture.stopServer();
34+
public void loadsOfConnects() {
35+
try {
36+
for (int i = 0; i < 1000; i++) {
37+
log.info("Try " + i);
38+
fixture.start();
39+
fixture.setupConnectedDefaultClient();
40+
fixture.stopClient();
41+
fixture.stopServer();
42+
}
43+
} catch (Exception e) {
44+
fail(e.getMessage());
4045
}
46+
4147
}
4248

4349
}

src/test/java/net/schmizz/sshj/keyprovider/OpenSSHKeyFileTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,10 +251,10 @@ public void shouldSuccessfullyLoadSignedDSAPublicKey() throws IOException {
251251
}
252252

253253
@Before
254-
public void setup()
255-
throws UnsupportedEncodingException, GeneralSecurityException {
256-
if (!SecurityUtils.isBouncyCastleRegistered())
254+
public void checkBCRegistration() {
255+
if (!SecurityUtils.isBouncyCastleRegistered()) {
257256
throw new AssertionError("bouncy castle needed");
257+
}
258258
}
259259

260260
private String readFile(String pathname)

0 commit comments

Comments
 (0)