Ref: add new static analyser rule: category/java/bestpractices.xml/LiteralsFirstInComparisons

This commit is contained in:
Laurent Clouet
2024-06-07 14:35:47 +00:00
parent 824dfe4ef6
commit 0a7f1f9f1b
14 changed files with 29 additions and 28 deletions

View File

@@ -15,6 +15,7 @@
<rule ref="category/java/bestpractices.xml/AvoidUsingHardCodedIP" /> <rule ref="category/java/bestpractices.xml/AvoidUsingHardCodedIP" />
<rule ref="category/java/bestpractices.xml/CheckResultSet" /> <rule ref="category/java/bestpractices.xml/CheckResultSet" />
<rule ref="category/java/bestpractices.xml/MissingOverride" /> <rule ref="category/java/bestpractices.xml/MissingOverride" />
<rule ref="category/java/bestpractices.xml/LiteralsFirstInComparisons" />
<rule ref="category/java/bestpractices.xml/OneDeclarationPerLine" /> <rule ref="category/java/bestpractices.xml/OneDeclarationPerLine" />
<rule ref="category/java/bestpractices.xml/PrimitiveWrapperInstantiation" /> <rule ref="category/java/bestpractices.xml/PrimitiveWrapperInstantiation" />
<rule ref="category/java/bestpractices.xml/UnusedFormalParameter" /> <rule ref="category/java/bestpractices.xml/UnusedFormalParameter" />

View File

@@ -278,7 +278,7 @@ import lombok.Data;
try { try {
String extension = file.getName().substring(file.getName().lastIndexOf('.')).toLowerCase(); String extension = file.getName().substring(file.getName().lastIndexOf('.')).toLowerCase();
String name = file.getName().substring(0, file.getName().length() - 1 * extension.length()); String name = file.getName().substring(0, file.getName().length() - 1 * extension.length());
if (extension.equals(".zip") || extension.equals(".wool")) { if (".zip".equals(extension) || ".wool".equals(extension)) {
// check if the md5 of the file is ok // check if the md5 of the file is ok
String md5_local = Utils.md5(file.getAbsolutePath()); String md5_local = Utils.md5(file.getAbsolutePath());
@@ -344,7 +344,7 @@ import lombok.Data;
try { try {
String extension = file.getName().substring(file.getName().lastIndexOf('.')).toLowerCase(); String extension = file.getName().substring(file.getName().lastIndexOf('.')).toLowerCase();
String name = file.getName().substring(0, file.getName().length() - 1 * extension.length()); String name = file.getName().substring(0, file.getName().length() - 1 * extension.length());
if (extension.equals(".zip") || extension.equals(".wool")) { if (".zip".equals(extension) || ".wool".equals(extension)) {
// check if the md5 of the file is ok // check if the md5 of the file is ok
String md5_local = Utils.md5(file.getAbsolutePath()); String md5_local = Utils.md5(file.getAbsolutePath());

View File

@@ -746,7 +746,7 @@ import java.util.regex.Pattern;
} }
} }
} }
else if (getUpdateRenderingStatusMethod().equals(Job.UPDATE_METHOD_BY_TILE)) { else if (Job.UPDATE_METHOD_BY_TILE.equals(getUpdateRenderingStatusMethod())) {
String search = " Tile "; String search = " Tile ";
int index = line.lastIndexOf(search); int index = line.lastIndexOf(search);
if (index != -1) { if (index != -1) {

View File

@@ -89,7 +89,7 @@ public final class Log {
try { try {
int checkpointToWrite = (point_ > 0 ? point_ : this.lastCheckPoint); int checkpointToWrite = (point_ > 0 ? point_ : this.lastCheckPoint);
if (msg_.equals("") == false) { if ("".equals(msg_) == false) {
String 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

@@ -401,7 +401,7 @@ public class Server extends Thread {
jobData.getRenderTask().getUseGpu() == 1, jobData.getRenderTask().getRendererInfos().getCommandline(), validationUrl, jobData.getRenderTask().getUseGpu() == 1, jobData.getRenderTask().getRendererInfos().getCommandline(), validationUrl,
jobData.getRenderTask().getScript(), jobData.getRenderTask().getChunks(), jobData.getRenderTask().getRendererInfos().getMd5(), jobData.getRenderTask().getScript(), jobData.getRenderTask().getChunks(), jobData.getRenderTask().getRendererInfos().getMd5(),
jobData.getRenderTask().getName(), jobData.getRenderTask().getPassword(), jobData.getRenderTask().getName(), jobData.getRenderTask().getPassword(),
jobData.getRenderTask().getSynchronousUpload().equals("1"), jobData.getRenderTask().getRendererInfos().getUpdateMethod()); "1".equals(jobData.getRenderTask().getSynchronousUpload()), jobData.getRenderTask().getRendererInfos().getUpdateMethod());
} }
catch (SheepItException e) { catch (SheepItException e) {
throw e; throw e;
@@ -688,7 +688,7 @@ public class Server extends Thread {
try { try {
String extension = local_file.getName().substring(local_file.getName().lastIndexOf('.')).toLowerCase(); String extension = local_file.getName().substring(local_file.getName().lastIndexOf('.')).toLowerCase();
String name = local_file.getName().substring(0, local_file.getName().length() - 1 * extension.length()); String name = local_file.getName().substring(0, local_file.getName().length() - 1 * extension.length());
if (extension.equals(".zip") || extension.equals(".wool")) { if (".zip".equals(extension) || ".wool".equals(extension)) {
// node_file.setAttribute("md5", name); // node_file.setAttribute("md5", name);
FileMD5 fileMD5 = new FileMD5(); FileMD5 fileMD5 = new FileMD5();
fileMD5.setMd5(name); fileMD5.setMd5(name);

View File

@@ -119,7 +119,7 @@ public class Linux extends OS {
if ((userLevel = reader.readLine()) != null) { if ((userLevel = reader.readLine()) != null) {
// Root user in *ix systems -independently of the alias used to login- has a id value of 0. On top of being a user with root capabilities, // Root user in *ix systems -independently of the alias used to login- has a id value of 0. On top of being a user with root capabilities,
// to support changing the priority the nice tool must be accessible from the current user // to support changing the priority the nice tool must be accessible from the current user
return (userLevel.equals("0")) & isNiceAvailable(); return ("0".equals(userLevel)) & isNiceAvailable();
} }
} }
catch (IOException e) { catch (IOException e) {

View File

@@ -89,7 +89,7 @@ public class Mac extends OS {
if ((userLevel = reader.readLine()) != null) { if ((userLevel = reader.readLine()) != null) {
// Root user in *ix systems -independently of the alias used to login- has a id value of 0. On top of being a user with root capabilities, // Root user in *ix systems -independently of the alias used to login- has a id value of 0. On top of being a user with root capabilities,
// to support changing the priority the nice tool must be accessible from the current user // to support changing the priority the nice tool must be accessible from the current user
return (userLevel.equals("0")) & isNiceAvailable(); return ("0".equals(userLevel)) & isNiceAvailable();
} }
} }
catch (IOException e) { catch (IOException e) {

View File

@@ -221,10 +221,10 @@ public class GuiSwing extends JFrame implements Gui {
this.showActivity(ActivityType.SETTINGS); this.showActivity(ActivityType.SETTINGS);
try { try {
if (client.getConfiguration().getTheme().equals("light")) { if ("light".equals(client.getConfiguration().getTheme())) {
UIManager.setLookAndFeel(new FlatLightLaf()); UIManager.setLookAndFeel(new FlatLightLaf());
} }
else if (client.getConfiguration().getTheme().equals("dark")) { else if ("dark".equals(client.getConfiguration().getTheme())) {
UIManager.setLookAndFeel(new FlatDarkLaf()); UIManager.setLookAndFeel(new FlatDarkLaf());
} }

View File

@@ -205,7 +205,7 @@ public class GuiText implements Gui {
.append(String.join("", Collections.nCopies(20 - (int)(progress / 5), " "))) .append(String.join("", Collections.nCopies(20 - (int)(progress / 5), " ")))
.append(']'); .append(']');
if (!this.eta.equals("")) { if ("".equals(this.eta) == false) {
progressBar.append(String.format(" ETA %s", this.eta)); progressBar.append(String.format(" ETA %s", this.eta));
} }

View File

@@ -236,7 +236,7 @@ public class GuiTextOneLine implements Gui {
.append(String.join("", Collections.nCopies(10 - (int) (progress / 10), " "))) .append(String.join("", Collections.nCopies(10 - (int) (progress / 10), " ")))
.append(']'); .append(']');
if (!this.eta.equals("")) { if ("".equals(this.eta) == false) {
progressBar.append(String.format(" ETA %s", this.eta)); progressBar.append(String.format(" ETA %s", this.eta));
} }

View File

@@ -346,7 +346,7 @@ public class Worker {
} }
if (theme != null) { if (theme != null) {
if (!theme.equals("light") && !theme.equals("dark")) { if ("light".equals(theme) == false && "dark".equals(theme) == false) {
System.err.println("ERROR: The entered theme (-theme parameter) doesn't exist. Please choose either 'light' or 'dark'"); System.err.println("ERROR: The entered theme (-theme parameter) doesn't exist. Please choose either 'light' or 'dark'");
System.exit(2); System.exit(2);
} }
@@ -406,7 +406,7 @@ public class Worker {
} }
if (shutdownMode != null) { if (shutdownMode != null) {
if (shutdownMode.equalsIgnoreCase("wait") || shutdownMode.equalsIgnoreCase("hard")) { if ("wait".equalsIgnoreCase(shutdownMode) || "hard".equalsIgnoreCase(shutdownMode)) {
config.setShutdownMode(shutdownMode.toLowerCase()); config.setShutdownMode(shutdownMode.toLowerCase());
} }
else { else {
@@ -425,7 +425,7 @@ public class Worker {
} }
System.out.println("=============================================================================="); System.out.println("==============================================================================");
if (config.getShutdownMode().equals("wait")) { if ("wait".equals(config.getShutdownMode())) {
System.out.println(String.format( System.out.println(String.format(
"WARNING!\n\nThe client will stop requesting new jobs at %s.\nTHE EFFECTIVE SHUTDOWN MIGHT OCCUR LATER THAN THE REQUESTED TIME AS THE UPLOAD\nQUEUE MUST BE FULLY UPLOADED BEFORE THE SHUTDOWN PROCESS STARTS.\n\nIf you want to shutdown the computer sharp at the specified time, please\ninclude the '-shutdown-mode hard' parameter in the application call", "WARNING!\n\nThe client will stop requesting new jobs at %s.\nTHE EFFECTIVE SHUTDOWN MIGHT OCCUR LATER THAN THE REQUESTED TIME AS THE UPLOAD\nQUEUE MUST BE FULLY UPLOADED BEFORE THE SHUTDOWN PROCESS STARTS.\n\nIf you want to shutdown the computer sharp at the specified time, please\ninclude the '-shutdown-mode hard' parameter in the application call",
shutdownTime)); shutdownTime));

View File

@@ -181,12 +181,12 @@ public class Settings implements Activity {
lightMode = new JRadioButton("Light"); lightMode = new JRadioButton("Light");
lightMode.setActionCommand("light"); lightMode.setActionCommand("light");
lightMode.setSelected(config.getTheme().equals("light")); lightMode.setSelected("light".equals(config.getTheme()));
lightMode.addActionListener(new ApplyThemeAction()); lightMode.addActionListener(new ApplyThemeAction());
darkMode = new JRadioButton("Dark"); darkMode = new JRadioButton("Dark");
darkMode.setActionCommand("dark"); darkMode.setActionCommand("dark");
darkMode.setSelected(config.getTheme().equals("dark")); darkMode.setSelected("dark".equals(config.getTheme()));
darkMode.addActionListener(new ApplyThemeAction()); darkMode.addActionListener(new ApplyThemeAction());
themePanel.add(lightMode); themePanel.add(lightMode);
@@ -590,10 +590,10 @@ public class Settings implements Activity {
private void applyTheme(String theme_) { private void applyTheme(String theme_) {
try { try {
if (theme_.equals("light")) { if ("light".equals(theme_)) {
UIManager.setLookAndFeel(new FlatLightLaf()); UIManager.setLookAndFeel(new FlatLightLaf());
} }
else if (theme_.equals("dark")) { else if ("dark".equals(theme_)) {
UIManager.setLookAndFeel(new FlatDarkLaf()); UIManager.setLookAndFeel(new FlatDarkLaf());
} }

View File

@@ -309,7 +309,7 @@ public class Working implements Activity {
public void setStatus(String msg_, boolean overwriteSuspendedMsg) { public void setStatus(String msg_, boolean overwriteSuspendedMsg) {
Client client = parent.getClient(); Client client = parent.getClient();
if (!msg_.equals("")) { if ("".equals(msg_) == false) {
this.previousStatus = msg_; this.previousStatus = msg_;
} }

View File

@@ -35,32 +35,32 @@ public class CLIInputActionHandler implements CLIInputListener {
if (client == null) { if (client == null) {
return; return;
} }
if (command.equalsIgnoreCase("block")) { if ("block".equalsIgnoreCase(command)) {
Job job = client.getRenderingJob(); Job job = client.getRenderingJob();
if (job != null) { if (job != null) {
job.block(); job.block();
} }
} }
else if (command.equalsIgnoreCase("resume")) { else if ("resume".equalsIgnoreCase(command)) {
client.resume(); client.resume();
} }
else if (command.equalsIgnoreCase("pause")) { else if ("pause".equalsIgnoreCase(command)) {
client.suspend(); client.suspend();
} }
else if (command.equalsIgnoreCase("stop")) { else if ("stop".equalsIgnoreCase(command)) {
client.askForStop(); client.askForStop();
} }
else if (command.equalsIgnoreCase("status")) { else if ("status".equalsIgnoreCase(command)) {
displayStatus(client); displayStatus(client);
} }
else if (command.equalsIgnoreCase("cancel")) { else if ("cancel".equalsIgnoreCase(command)) {
client.cancelStop(); client.cancelStop();
} }
else if (command.equalsIgnoreCase("quit")) { else if ("quit".equalsIgnoreCase(command)) {
client.stop(); client.stop();
System.exit(0); System.exit(0);
} }
else if ((command.length() > priorityLength) && (command.substring(0, priorityLength).equalsIgnoreCase("priority"))) { else if ((command.length() > priorityLength) && "priority".equalsIgnoreCase(command.substring(0, priorityLength))) {
changePriority(client, command.substring(priorityLength)); changePriority(client, command.substring(priorityLength));
} }
else { else {