Merge branch 'pmd/new-rule' into 'master'

Ref: add new static analyser rule: bestpractices.xml/UnusedAssignment

See merge request sheepitrenderfarm/client!313
This commit is contained in:
Laurent Clouet
2024-06-06 01:05:27 +00:00
8 changed files with 20 additions and 29 deletions

View File

@@ -9,6 +9,7 @@
SheepIt client custom rules SheepIt client custom rules
</description> </description>
<rule ref="category/java/bestpractices.xml/UnusedAssignment" />
<rule ref="category/java/bestpractices.xml/ArrayIsStoredDirectly" /> <rule ref="category/java/bestpractices.xml/ArrayIsStoredDirectly" />
<rule ref="category/java/bestpractices.xml/AbstractClassWithoutAbstractMethod" /> <rule ref="category/java/bestpractices.xml/AbstractClassWithoutAbstractMethod" />
<rule ref="category/java/bestpractices.xml/AvoidUsingHardCodedIP" /> <rule ref="category/java/bestpractices.xml/AvoidUsingHardCodedIP" />

View File

@@ -163,7 +163,7 @@ import java.util.regex.Pattern;
gui.status("Rendering"); gui.status("Rendering");
RenderProcess process = getProcessRender(); RenderProcess process = getProcessRender();
Timer timerOfMaxRenderTime = null; Timer timerOfMaxRenderTime = null;
String core_script = ""; String core_script;
// When sending Ctrl+C to the terminal it also get's sent to all subprocesses e.g. also the render process. // When sending Ctrl+C to the terminal it also get's sent to all subprocesses e.g. also the render process.
// The java program handles Ctrl+C but the renderer quits on Ctrl+C. // The java program handles Ctrl+C but the renderer quits on Ctrl+C.
// This script causes the renderer to ignore Ctrl+C. // This script causes the renderer to ignore Ctrl+C.

View File

@@ -85,13 +85,12 @@ public class Log {
if (LEVEL_DEBUG.equals(level_) && this.debugLevel == false) { if (LEVEL_DEBUG.equals(level_) && this.debugLevel == false) {
return; return;
} }
String line = null;
try { try {
int checkpointToWrite = (point_ > 0 ? point_ : this.lastCheckPoint); int checkpointToWrite = (point_ > 0 ? point_ : this.lastCheckPoint);
if (msg_.equals("") == false) { if (msg_.equals("") == false) {
line = this.dateFormat.format(new Date()) + " (" + level_ + ") " + msg_; String line = this.dateFormat.format(new Date()) + " (" + level_ + ") " + msg_;
if (this.checkpoints.containsKey(checkpointToWrite) && this.checkpoints.get(checkpointToWrite) != null) { if (this.checkpoints.containsKey(checkpointToWrite) && this.checkpoints.get(checkpointToWrite) != null) {
this.checkpoints.get(checkpointToWrite).add(line); this.checkpoints.get(checkpointToWrite).add(line);
} }

View File

@@ -197,7 +197,7 @@ public class Server extends Thread {
public Error.Type getConfiguration() { public Error.Type getConfiguration() {
OS os = OS.getOS(); OS os = OS.getOS();
String publickey = null; String publickey;
try { try {
HttpUrl.Builder remoteURL = Objects.requireNonNull(HttpUrl.parse(this.base_url + "/server/config.php")).newBuilder(); HttpUrl.Builder remoteURL = Objects.requireNonNull(HttpUrl.parse(this.base_url + "/server/config.php")).newBuilder();
FormBody formBody = new FormBody.Builder() FormBody formBody = new FormBody.Builder()
@@ -240,12 +240,9 @@ public class Server extends Thread {
if (ServerCode.fromInt(serverConfig.getStatus()) != ServerCode.OK) { if (ServerCode.fromInt(serverConfig.getStatus()) != ServerCode.OK) {
return Error.ServerCodeToType(ServerCode.fromInt(serverConfig.getStatus())); return Error.ServerCodeToType(ServerCode.fromInt(serverConfig.getStatus()));
} }
publickey = serverConfig.getPublickey(); publickey = serverConfig.getPublickey();
if (publickey.isEmpty()) { if (publickey.isEmpty() == false) {
publickey = null;
}
else {
this.user_config.setPassword(publickey); this.user_config.setPassword(publickey);
} }
} }
@@ -442,12 +439,11 @@ public class Server extends Thread {
} }
Request request = builder.build(); Request request = builder.build();
Response response = null;
try { try {
response = httpClient.newCall(request).execute(); Response response = httpClient.newCall(request).execute();
if (!response.isSuccessful()) { if (response.isSuccessful() == false) {
this.log.error("Received unsuccessful HTTP response " + response); this.log.error("Received unsuccessful HTTP response " + response);
} }
@@ -470,10 +466,9 @@ public class Server extends Thread {
} }
Request request = builder.build(); Request request = builder.build();
Response response = null;
try { try {
response = httpClient.newCall(request).execute(); Response response = httpClient.newCall(request).execute();
if (checkIsSuccessful && !response.isSuccessful()) { if (checkIsSuccessful && !response.isSuccessful()) {
throw new IOException("Unexpected code " + response); throw new IOException("Unexpected code " + response);
@@ -509,7 +504,7 @@ public class Server extends Thread {
long size = response.body().contentLength(); long size = response.body().contentLength();
// only update the gui every 1MB // only update the gui every 1MB
byte[] buffer = new byte[1024 * 1024]; byte[] buffer = new byte[1024 * 1024];
int len = 0; int len;
long written = 0; long written = 0;
if (size != -1) { if (size != -1) {

View File

@@ -256,9 +256,8 @@ public class SettingsLoader {
Properties configFileProp = new Properties(); Properties configFileProp = new Properties();
if (new File(path).exists()) { if (new File(path).exists()) {
InputStream input = null;
try { try {
input = new FileInputStream(path); InputStream input = new FileInputStream(path);
configFileProp.load(input); configFileProp.load(input);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();

View File

@@ -112,7 +112,7 @@ public class Utils {
if (password != null) { if (password != null) {
zipInputStream.setPassword(password); zipInputStream.setPassword(password);
} }
LocalFileHeader fileHeader = null; LocalFileHeader fileHeader;
while ((fileHeader = zipInputStream.getNextEntry()) != null) { while ((fileHeader = zipInputStream.getNextEntry()) != null) {
String outFilePath = destinationDirectory + File.separator + fileHeader.getFileName(); String outFilePath = destinationDirectory + File.separator + fileHeader.getFileName();
File outFile = new File(outFilePath); File outFile = new File(outFilePath);
@@ -130,7 +130,7 @@ public class Utils {
FileOutputStream os = new FileOutputStream(outFile); FileOutputStream os = new FileOutputStream(outFile);
int readLen = -1; int readLen;
byte[] buff = new byte[1024]; byte[] buff = new byte[1024];
//Loop until End of File and write the contents to the output stream //Loop until End of File and write the contents to the output stream
@@ -354,8 +354,8 @@ public class Utils {
* Examples: 4,20GB, 20,00TB, 3,69MB * Examples: 4,20GB, 20,00TB, 3,69MB
*/ */
public static String formatDataConsumption(long bytes) { public static String formatDataConsumption(long bytes) {
float divider = 0; float divider;
String suffix = ""; String suffix;
if (bytes > 1099511627776f) { // 1TB if (bytes > 1099511627776f) { // 1TB
divider = 1099511627776f; divider = 1099511627776f;

View File

@@ -164,7 +164,7 @@ public class Nvidia implements GPULister {
if (path == null) { if (path == null) {
return null; return null;
} }
CUDA cudalib = null; CUDA cudalib;
try { try {
cudalib = (CUDA) Native.load(path, CUDA.class); cudalib = (CUDA) Native.load(path, CUDA.class);
} }
@@ -180,9 +180,7 @@ public class Nvidia implements GPULister {
return null; return null;
} }
int result = CUresult.CUDA_ERROR_UNKNOWN; int result = cudalib.cuInit(0);
result = cudalib.cuInit(0);
if (result != CUresult.CUDA_SUCCESS) { if (result != CUresult.CUDA_SUCCESS) {
System.out.println("Nvidia::getGpus cuInit failed: " + getCudaErrorString(result) + " (" + result + ")"); System.out.println("Nvidia::getGpus cuInit failed: " + getCudaErrorString(result) + " (" + result + ")");
if (result == CUresult.CUDA_ERROR_UNKNOWN) { if (result == CUresult.CUDA_ERROR_UNKNOWN) {
@@ -269,7 +267,7 @@ public class Nvidia implements GPULister {
return null; return null;
} }
NVML nvml = null; NVML nvml;
try { try {
nvml = Native.load(os.getNVMLLib(), NVML.class); nvml = Native.load(os.getNVMLLib(), NVML.class);
} }

View File

@@ -48,9 +48,8 @@ public class Windows extends OS {
@Override public Process exec(List<String> command, Map<String, String> env) throws IOException { @Override public Process exec(List<String> command, Map<String, String> env) throws IOException {
// disable a popup because the renderer might crash (seg fault) // disable a popup because the renderer might crash (seg fault)
Kernel32Lib kernel32lib = null;
try { try {
kernel32lib = (Kernel32Lib) Native.load(Kernel32Lib.path, Kernel32Lib.class); Kernel32Lib kernel32lib = (Kernel32Lib) Native.load(Kernel32Lib.path, Kernel32Lib.class);
kernel32lib.SetErrorMode(Kernel32Lib.SEM_NOGPFAULTERRORBOX); kernel32lib.SetErrorMode(Kernel32Lib.SEM_NOGPFAULTERRORBOX);
} }
catch (UnsatisfiedLinkError e) { catch (UnsatisfiedLinkError e) {