force PMD v7

PMD v7: fix new design/SimplifyBooleanReturns matches
PMD v7: fix new bestpractices/UnusedAssignment matches
PMD v7: fix new bestpractices/LiteralsFirstInComparisons matches
PMD v7: fix new codestyle/UnnecessaryFullyQualifiedName matches
PMD v7: fix new bestpractices/LooseCoupling matches
PMD rules: bestpractices/UseVarargs
PMD rules: sort lines
This commit is contained in:
M*C*O
2024-06-10 16:34:12 +00:00
committed by Laurent Clouet
parent 46f893327d
commit 48f3761656
17 changed files with 121 additions and 122 deletions

View File

@@ -9,12 +9,13 @@ import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Path;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.List;
import java.util.NoSuchElementException;
public class ChunkInputStream extends InputStream {
@NonNull private final ArrayDeque<Path> chunkPaths;
@NonNull private final Deque<Path> chunkPaths;
@NonNull private BufferedInputStream currentStream;
/**

View File

@@ -619,7 +619,7 @@ import okhttp3.HttpUrl;
// Insert the info at the beginning of the error log
writer.write(logHeader.toString().getBytes());
Optional<ArrayList<String>> logs = this.log.getForCheckPoint(step);
Optional<List<String>> logs = this.log.getForCheckPoint(step);
if (logs.isPresent()) {
for (String line : logs.get()) {
writer.write(line.getBytes());
@@ -799,7 +799,7 @@ import okhttp3.HttpUrl;
int threads = Math.max(1, Math.min(total, 12)); // at least one thread, to avoid IllegalArgumentException if total = 0
ExecutorService executor = Executors.newFixedThreadPool(threads);
ArrayList<Callable<Error.Type>> tasks = new ArrayList<>();
List<Callable<Error.Type>> tasks = new ArrayList<>();
this.gui.getDownloadProgress().reset("Downloading project");
@@ -944,6 +944,7 @@ import okhttp3.HttpUrl;
return 0;
}
@SuppressWarnings("unused") // Suppress false positive about this.isValidatingJob - PMD rule cannot detect time-sensitive reads
protected Error.Type confirmJob(Job ajob, int checkpoint) {
String urlReal = String.format(LOCALE, "%s&rendertime=%d&preptime=%d&memoryused=%s", ajob.getValidationUrl(), ajob.getProcessRender().getRenderDuration(), ajob.getProcessRender().getScenePrepDuration(),
ajob.getProcessRender().getPeakMemoryUsed());

View File

@@ -370,11 +370,11 @@ import lombok.Data;
* @return an ArrayList of Strings containing all logs of the FSHealth check
*/
public List<String> filesystemHealthCheck() {
ArrayList<String> logs = new ArrayList<>();
List<String> logs = new ArrayList<>();
String f = "FSHealth: ";
logs.add(f + "FilesystemHealthCheck started");
ArrayList<File> dirsToCheck = new ArrayList<>();
ArrayList<File> dirsChecked = new ArrayList<>();
List<File> dirsToCheck = new ArrayList<>();
List<File> dirsChecked = new ArrayList<>();
dirsToCheck.add(workingDirectory.getAbsoluteFile());
if (sharedDownloadsDirectory != null && dirsToCheck.contains(sharedDownloadsDirectory.getAbsoluteFile()) == false) {
dirsToCheck.add(sharedDownloadsDirectory.getAbsoluteFile());

View File

@@ -128,13 +128,13 @@ public class Error {
}
public static ServerCode fromInt(int val) {
ServerCode[] As = ServerCode.values();
ServerCode[] As = values();
for (ServerCode A : As) {
if (A.getValue() == val) {
return A;
}
}
return ServerCode.UNKNOWN;
return UNKNOWN;
}
}

View File

@@ -470,7 +470,7 @@ import java.util.regex.Pattern;
// Once the process is finished (either finished successfully or with an error) move back to
// base icon (isolated S with no progress bar)
gui.updateTrayIcon(Job.SHOW_BASE_ICON);
gui.updateTrayIcon(SHOW_BASE_ICON);
return Error.Type.RENDERER_OUT_OF_MEMORY;
}
@@ -494,7 +494,7 @@ import java.util.regex.Pattern;
}
// Put back base icon
gui.updateTrayIcon(Job.SHOW_BASE_ICON);
gui.updateTrayIcon(SHOW_BASE_ICON);
process.kill();
maybeCleanWorkingDir(error);
for (String logline : configuration.filesystemHealthCheck()) {
@@ -545,7 +545,7 @@ import java.util.regex.Pattern;
}
// Put back base icon
gui.updateTrayIcon(Job.SHOW_BASE_ICON);
gui.updateTrayIcon(SHOW_BASE_ICON);
log.debug("end of rendering");
@@ -714,7 +714,7 @@ import java.util.regex.Pattern;
}
private void updateRenderingStatus(String line, int progress) {
if (getUpdateRenderingStatusMethod() == null || getUpdateRenderingStatusMethod().equals(Job.UPDATE_METHOD_BY_REMAINING_TIME)) {
if (getUpdateRenderingStatusMethod() == null || UPDATE_METHOD_BY_REMAINING_TIME.equals(getUpdateRenderingStatusMethod())) {
String search_remaining = "remaining:";
int index = line.toLowerCase().indexOf(search_remaining);
if (index != -1) {
@@ -760,7 +760,7 @@ import java.util.regex.Pattern;
}
}
}
else if (Job.UPDATE_METHOD_BY_TILE.equals(getUpdateRenderingStatusMethod())) {
else if (UPDATE_METHOD_BY_TILE.equals(getUpdateRenderingStatusMethod())) {
String search = " Tile ";
int index = line.lastIndexOf(search);
if (index != -1) {

View File

@@ -29,6 +29,7 @@ import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@@ -39,7 +40,7 @@ public final class Log {
private static Log instance = null;
private Map<Integer, ArrayList<String>> checkpoints = new HashMap<Integer, ArrayList<String>>();
private Map<Integer, List<String>> checkpoints = new HashMap<>();
private int lastCheckPoint;
private DateFormat dateFormat;
@@ -120,7 +121,7 @@ public final class Log {
return this.lastCheckPoint;
}
public Optional<ArrayList<String>> getForCheckPoint(int point_) {
public Optional<List<String>> getForCheckPoint(int point_) {
return Optional.ofNullable(this.checkpoints.get(point_));
}
@@ -149,8 +150,8 @@ public final class Log {
}
public static synchronized void printCheckPoint(int point_) {
Log log = Log.getInstance(null);
Optional<ArrayList<String>> logs = log.getForCheckPoint(point_);
Log log = getInstance(null);
Optional<List<String>> logs = log.getForCheckPoint(point_);
if (logs.isPresent()) {
for (String alog : logs.get()) {
System.out.println(alog);

View File

@@ -178,7 +178,7 @@ public class Server extends Thread {
}
}
try {
Thread.sleep(60 * 1000); // 1min
sleep(60 * 1000); // 1min
}
catch (InterruptedException e) {
return;

View File

@@ -502,7 +502,7 @@ public class SettingsLoader {
if (device != null) {
config.setGPUDevice(device);
}
else if (config.getUIType() != null && (config.getUIType().equals(GuiText.type) || config.getUIType().equals(GuiTextOneLine.type))) {
else if (config.getUIType() != null && (GuiText.type.equals(config.getUIType()) || GuiTextOneLine.type.equals(config.getUIType()))) {
System.err.println("SettingsLoader::merge could not find specified GPU");
System.exit(2);
}
@@ -533,7 +533,7 @@ public class SettingsLoader {
}
if (config.getTheme() == null) {
if (this.theme != null && (this.theme.getValue().equals("dark") || this.theme.getValue().equals("light"))) {
if (this.theme != null && ("dark".equals(this.theme.getValue()) || "light".equals(this.theme.getValue()))) {
config.setTheme(this.theme.getValue());
}
else {
@@ -547,7 +547,7 @@ public class SettingsLoader {
// if the user has invoked the app with --no-systray, then we just overwrite the existing configuration with (boolean)false. If no parameter has been
// specified and the settings file contains use-systray=false, then deactivate as well.
if (!config.isUseSysTray() || (config.isUseSysTray() && useSysTray != null && useSysTray.getValue().equals("false"))) {
if (!config.isUseSysTray() || (config.isUseSysTray() && useSysTray != null && "false".equals(useSysTray.getValue()))) {
config.setUseSysTray(false);
}

View File

@@ -331,7 +331,7 @@ public class Utils {
mimeType = URLConnection.guessContentTypeFromName(file);
}
if (mimeType == null || (mimeType.equals("image/aces") && file.toLowerCase().endsWith(".exr"))) {
if (mimeType == null || ("image/aces".equals(mimeType) && file.toLowerCase().endsWith(".exr"))) {
try {
String extension = file.substring(file.lastIndexOf('.'));
mimeType = mimeTypes.get(extension);

View File

@@ -68,12 +68,8 @@ public class GPU {
public static boolean hasHIPDevices() {
OS os = OS.getOS();
if (os instanceof Windows) { // for now we only allow AMD on Windows
return HIP.hasHIPDevices();
}
else {
return false;
}
// for now we only allow AMD on Windows
return os instanceof Windows && HIP.hasHIPDevices();
}
public static GPUDevice getGPUDevice(String deviceId) {

View File

@@ -164,7 +164,7 @@ public class WinProcess {
}
private List<WinProcess> getChildren() throws IOException {
ArrayList<WinProcess> result = new ArrayList<WinProcess>();
List<WinProcess> result = new ArrayList<>();
WinNT.HANDLE hSnap = this.kernel32lib.CreateToolhelp32Snapshot(Kernel32Lib.TH32CS_SNAPPROCESS, new DWORD(0));
Kernel32Lib.PROCESSENTRY32.ByReference ent = new Kernel32Lib.PROCESSENTRY32.ByReference();

View File

@@ -193,7 +193,7 @@ public class GuiSwing extends JFrame implements Gui {
setTitle(title);
setSize(WIDTH, 760);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setDefaultCloseOperation(EXIT_ON_CLOSE);
panel = new JPanel();
panel.setLayout(new GridBagLayout());
@@ -406,7 +406,7 @@ public class GuiSwing extends JFrame implements Gui {
if (sysTray != null && SystemTray.isSupported()) {
sysTray.remove(trayIcon);
setVisible(true);
setExtendedState(getExtendedState() & ~JFrame.ICONIFIED & JFrame.NORMAL); // for toFront and requestFocus to actually work
setExtendedState(getExtendedState() & ~ICONIFIED & NORMAL); // for toFront and requestFocus to actually work
toFront();
requestFocus();
}

View File

@@ -127,7 +127,7 @@ public class Worker {
new Worker().doMain(args);
}
public void doMain(String[] args) {
public void doMain(String... args) {
CmdLineParser parser = new CmdLineParser(this);
try {
parser.parseArgument(args);

View File

@@ -28,6 +28,7 @@ import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.io.File;
import java.net.MalformedURLException;
import java.util.Dictionary;
import java.util.Hashtable;
import java.util.LinkedList;
import java.util.List;
@@ -357,7 +358,7 @@ public class Settings implements Activity {
step += 1000000;
display = (double) all_ram / (double) step;
}
Hashtable<Integer, JLabel> labelTable = new Hashtable<Integer, JLabel>();
Dictionary<Integer, JLabel> labelTable = new Hashtable<>();
for (int g = 0; g < all_ram; g += step) {
labelTable.put(g, new JLabel("" + (g / 1000000)));
}
@@ -395,7 +396,7 @@ public class Settings implements Activity {
// -19 is highest priority
boolean high_priority_support = os.isHighPrioritySupported();
priority = new JSlider(high_priority_support ? -19 : 0, 19);
Hashtable<Integer, JLabel> labelTablePriority = new Hashtable<>();
Dictionary<Integer, JLabel> labelTablePriority = new Hashtable<>();
labelTablePriority.put(high_priority_support ? -19 : 0, new JLabel("Low"));
labelTablePriority.put(19, new JLabel("High"));
priority.setLabelTable(labelTablePriority);

View File

@@ -45,7 +45,7 @@ public class CLIInputObserver implements Runnable {
in = new BufferedReader(new InputStreamReader(System.in));
String line = "";
while ((line != null) && (line.equalsIgnoreCase("quit") == false)) {
while ((line != null) && ("quit".equalsIgnoreCase(line) == false)) {
try {
line = in.readLine();
}