Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
<dependency>
<groupId>org.connectbot</groupId>
<artifactId>sshlib</artifactId>
<version>2.2.24</version>
<version>2.2.42</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/org/metricshub/ssh/SshClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
import java.io.OutputStream;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.Vector;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -327,7 +327,7 @@
.append("\t")
.append(fileAttributes.atime.toString())
.append("\t-\t")
.append(Integer.toString(fileAttributes.permissions & 0000777, 8))

Check warning on line 330 in src/main/java/org/metricshub/ssh/SshClient.java

View workflow job for this annotation

GitHub Actions / PMD

Error Prone AvoidUsingOctalValues

Do not start a literal by 0 unless its an octal value
.append("\t")
.append(fileAttributes.size.toString())
.append("\t-\t")
Expand Down Expand Up @@ -355,8 +355,7 @@
StringBuilder resultBuilder
) throws IOException {
if (depth <= 15) {
@SuppressWarnings("unchecked")
Vector<SFTPv3DirectoryEntry> pathContents = sftpClient.ls(remoteDirectoryPath);
List<SFTPv3DirectoryEntry> pathContents = sftpClient.ls(remoteDirectoryPath);

// Fix the remoteDirectoryPath (without the last '/')
if (remoteDirectoryPath.endsWith("/")) {
Expand All @@ -374,17 +373,17 @@
SFTPv3FileAttributes fileAttributes = file.attributes;
String filePath = remoteDirectoryPath + "/" + filename;

if ((fileAttributes.permissions & 0120000) == 0120000) {

Check warning on line 376 in src/main/java/org/metricshub/ssh/SshClient.java

View workflow job for this annotation

GitHub Actions / PMD

Error Prone AvoidUsingOctalValues

Do not start a literal by 0 unless its an octal value

Check warning on line 376 in src/main/java/org/metricshub/ssh/SshClient.java

View workflow job for this annotation

GitHub Actions / PMD

Error Prone AvoidUsingOctalValues

Do not start a literal by 0 unless its an octal value
// Symbolic link
continue;
}

// CHECKSTYLE:OFF
if (
((fileAttributes.permissions & 0100000) == 0100000) ||

Check warning on line 383 in src/main/java/org/metricshub/ssh/SshClient.java

View workflow job for this annotation

GitHub Actions / PMD

Error Prone AvoidUsingOctalValues

Do not start a literal by 0 unless its an octal value

Check warning on line 383 in src/main/java/org/metricshub/ssh/SshClient.java

View workflow job for this annotation

GitHub Actions / PMD

Error Prone AvoidUsingOctalValues

Do not start a literal by 0 unless its an octal value
((fileAttributes.permissions & 0060000) == 0060000) ||

Check warning on line 384 in src/main/java/org/metricshub/ssh/SshClient.java

View workflow job for this annotation

GitHub Actions / PMD

Error Prone AvoidUsingOctalValues

Do not start a literal by 0 unless its an octal value

Check warning on line 384 in src/main/java/org/metricshub/ssh/SshClient.java

View workflow job for this annotation

GitHub Actions / PMD

Error Prone AvoidUsingOctalValues

Do not start a literal by 0 unless its an octal value
((fileAttributes.permissions & 0020000) == 0020000) ||

Check warning on line 385 in src/main/java/org/metricshub/ssh/SshClient.java

View workflow job for this annotation

GitHub Actions / PMD

Error Prone AvoidUsingOctalValues

Do not start a literal by 0 unless its an octal value

Check warning on line 385 in src/main/java/org/metricshub/ssh/SshClient.java

View workflow job for this annotation

GitHub Actions / PMD

Error Prone AvoidUsingOctalValues

Do not start a literal by 0 unless its an octal value
((fileAttributes.permissions & 0140000) == 0140000)

Check warning on line 386 in src/main/java/org/metricshub/ssh/SshClient.java

View workflow job for this annotation

GitHub Actions / PMD

Error Prone AvoidUsingOctalValues

Do not start a literal by 0 unless its an octal value

Check warning on line 386 in src/main/java/org/metricshub/ssh/SshClient.java

View workflow job for this annotation

GitHub Actions / PMD

Error Prone AvoidUsingOctalValues

Do not start a literal by 0 unless its an octal value
) {
// Regular/Block/Character/Socket files
final Matcher m = fileMaskPattern.matcher(filename);
Expand All @@ -401,12 +400,12 @@
}
// CHECKSTYLE:ON

if ((fileAttributes.permissions & 0040000) == 0040000) {

Check warning on line 403 in src/main/java/org/metricshub/ssh/SshClient.java

View workflow job for this annotation

GitHub Actions / PMD

Error Prone AvoidUsingOctalValues

Do not start a literal by 0 unless its an octal value

Check warning on line 403 in src/main/java/org/metricshub/ssh/SshClient.java

View workflow job for this annotation

GitHub Actions / PMD

Error Prone AvoidUsingOctalValues

Do not start a literal by 0 unless its an octal value
// Directory
if (includeSubfolders) {
resultBuilder =
listSubDirectory(sftpClient, filePath, fileMaskPattern, includeSubfolders, depth, resultBuilder);
}

Check warning on line 408 in src/main/java/org/metricshub/ssh/SshClient.java

View workflow job for this annotation

GitHub Actions / PMD

Design CollapsibleIfStatements

This if statement could be combined with its parent
}
}
}
Expand Down Expand Up @@ -541,7 +540,7 @@
sftpClient.close();

// Metricshub Collection format
return out.toString();

Check warning on line 543 in src/main/java/org/metricshub/ssh/SshClient.java

View workflow job for this annotation

GitHub Actions / spotbugs

DM_DEFAULT_ENCODING

Found reliance on default encoding in org.metricshub.ssh.SshClient.readFile(String, Long, Integer): java.io.ByteArrayOutputStream.toString()
Raw output
 Found a call to a method which will perform a byte to String (or String to byte) conversion, and will assume that the default platform encoding is suitable. This will cause the application behavior to vary between platforms. Use an alternative API and specify a charset name or Charset object explicitly.
}

/**
Expand Down Expand Up @@ -611,24 +610,24 @@
/**
* Whether the command was successful or not
*/
public boolean success = true;

Check warning on line 613 in src/main/java/org/metricshub/ssh/SshClient.java

View workflow job for this annotation

GitHub Actions / spotbugs

URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD

Unread public/protected field: org.metricshub.ssh.SshClient$CommandResult.success
Raw output
 This field is never read. The field is public or protected, so perhaps it is intended to be used with classes not seen as part of the analysis. If not, consider removing it from the class.

/**
* How much time was taken by the execution itself (not counting the
* connection time), in seconds
*/
public float executionTime = 0;

Check warning on line 619 in src/main/java/org/metricshub/ssh/SshClient.java

View workflow job for this annotation

GitHub Actions / spotbugs

URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD

Unread public/protected field: org.metricshub.ssh.SshClient$CommandResult.executionTime
Raw output
 This field is never read. The field is public or protected, so perhaps it is intended to be used with classes not seen as part of the analysis. If not, consider removing it from the class.

/**
* The exit code (status) returned by the command (process return code).
* <code>null</code> if unsupported by the remote platform.
*/
public Integer exitStatus = null;

Check warning on line 625 in src/main/java/org/metricshub/ssh/SshClient.java

View workflow job for this annotation

GitHub Actions / spotbugs

URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD

Unread public/protected field: org.metricshub.ssh.SshClient$CommandResult.exitStatus
Raw output
 This field is never read. The field is public or protected, so perhaps it is intended to be used with classes not seen as part of the analysis. If not, consider removing it from the class.

/**
* The result of the command (stdout and stderr is merged into result)
*/
public String result = "";

Check warning on line 630 in src/main/java/org/metricshub/ssh/SshClient.java

View workflow job for this annotation

GitHub Actions / spotbugs

URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD

Unread public/protected field: org.metricshub.ssh.SshClient$CommandResult.result
Raw output
 This field is never read. The field is public or protected, so perhaps it is intended to be used with classes not seen as part of the analysis. If not, consider removing it from the class.
}

/**
Expand Down Expand Up @@ -712,7 +711,7 @@
// We completed in time

// Execution time (in seconds)
commandResult.executionTime = (currentTime - startTime) / 1000;

Check warning on line 714 in src/main/java/org/metricshub/ssh/SshClient.java

View workflow job for this annotation

GitHub Actions / spotbugs

ICAST_IDIV_CAST_TO_DOUBLE

Integral division result cast to double or float in org.metricshub.ssh.SshClient.executeCommand(String, int)
Raw output
This code casts the result of an integral division (e.g., int or long division) operation to double or float. Doing division on integers truncates the result to the integer value closest to zero. The fact that the result was cast to double suggests that this precision should have been retained. What was probably meant was to cast one or both of the operands to double before performing the division. Here is an example:

int x = 2;
int y = 5;
// Wrong: yields result 0.0
double value1 = x / y;

// Right: yields result 0.4
double value2 = x / (double) y;

// Read exit status, when available
waitForCondition = sshSession.waitForCondition(ChannelCondition.EXIT_STATUS, 5000);
Expand Down Expand Up @@ -744,7 +743,7 @@
openTerminal();

// Pipe specified InputStream to SSH's stdin -- use a separate thread
BufferedReader inputReader = new BufferedReader(new InputStreamReader(in));

Check warning on line 746 in src/main/java/org/metricshub/ssh/SshClient.java

View workflow job for this annotation

GitHub Actions / spotbugs

DM_DEFAULT_ENCODING

Found reliance on default encoding in org.metricshub.ssh.SshClient.interactiveSession(InputStream, OutputStream): new java.io.InputStreamReader(InputStream)
Raw output
 Found a call to a method which will perform a byte to String (or String to byte) conversion, and will assume that the default platform encoding is suitable. This will cause the application behavior to vary between platforms. Use an alternative API and specify a charset name or Charset object explicitly.
OutputStream outputWriter = sshSession.getStdin();
Thread stdinPipeThread = new Thread() {
@Override
Expand All @@ -752,12 +751,12 @@
try {
String line;
while ((line = inputReader.readLine()) != null) {
outputWriter.write(line.getBytes());

Check warning on line 754 in src/main/java/org/metricshub/ssh/SshClient.java

View workflow job for this annotation

GitHub Actions / spotbugs

DM_DEFAULT_ENCODING

Found reliance on default encoding in org.metricshub.ssh.SshClient$2.run(): String.getBytes()
Raw output
 Found a call to a method which will perform a byte to String (or String to byte) conversion, and will assume that the default platform encoding is suitable. This will cause the application behavior to vary between platforms. Use an alternative API and specify a charset name or Charset object explicitly.
outputWriter.write('\n');
}
} catch (Exception e) {
// Things ended up badly. Exit thread.
}

Check warning on line 759 in src/main/java/org/metricshub/ssh/SshClient.java

View workflow job for this annotation

GitHub Actions / PMD

Error Prone EmptyCatchBlock

Avoid empty catch blocks
// End of the input stream. We need to exit.
// Let's close the session so the main thread exits nicely.
sshSession.close();
Expand Down
Loading