diff --git a/src/main/java/com/rarchives/ripme/ui/MainWindow.java b/src/main/java/com/rarchives/ripme/ui/MainWindow.java index a6234333..6cd5c574 100644 --- a/src/main/java/com/rarchives/ripme/ui/MainWindow.java +++ b/src/main/java/com/rarchives/ripme/ui/MainWindow.java @@ -470,7 +470,7 @@ public final class MainWindow implements Runnable, RipStatusHandler { queuePanel.setBorder(emptyBorder); queuePanel.setVisible(false); queuePanel.setPreferredSize(new Dimension(300, 250)); - queueListModel = new DefaultListModel(); + queueListModel = new DefaultListModel<>(); JList queueList = new JList(queueListModel); queueList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); QueueMenuMouseListener queueMenuMouseListener; @@ -732,7 +732,7 @@ public final class MainWindow implements Runnable, RipStatusHandler { private void update() { try { String urlText = ripTextfield.getText().trim(); - if (urlText.equals("")) { + if (urlText.isEmpty()) { return; } if (!urlText.startsWith("http")) { @@ -1499,12 +1499,13 @@ public final class MainWindow implements Runnable, RipStatusHandler { */ if (Utils.getConfigBoolean("enable.finish.command", false)) { try { - String commandToRun = Utils.getConfigString("finish.command", "ls"); - commandToRun = commandToRun.replaceAll("%url%", url); - commandToRun = commandToRun.replaceAll("%path%", f.toAbsolutePath().toString()); + String cmdStr = Utils.getConfigString("finish.command", "ls"); + cmdStr = cmdStr.replaceAll("%url%", url); + cmdStr = cmdStr.replaceAll("%path%", f.toAbsolutePath().toString()); + // java dropped the exec string executor, as the string is only split very trivial. + // do the same at the moment, and split, to get rid of java-21 deprecation warning. + String[] commandToRun = cmdStr.split(" "); LOGGER.info("RUnning command " + commandToRun); - // code from: - // https://stackoverflow.com/questions/5711084/java-runtime-getruntime-getting-output-from-executing-a-command-line-program Process proc = Runtime.getRuntime().exec(commandToRun); BufferedReader stdInput = new BufferedReader(new InputStreamReader(proc.getInputStream())); diff --git a/src/main/java/com/rarchives/ripme/ui/UpdateUtils.java b/src/main/java/com/rarchives/ripme/ui/UpdateUtils.java index 4d2c7cac..128eabba 100644 --- a/src/main/java/com/rarchives/ripme/ui/UpdateUtils.java +++ b/src/main/java/com/rarchives/ripme/ui/UpdateUtils.java @@ -222,13 +222,14 @@ public class UpdateUtils { public static String createSha256(Path file) { try { MessageDigest digest = MessageDigest.getInstance("SHA-256"); - InputStream fis = Files.newInputStream(file); - int n = 0; - byte[] buffer = new byte[8192]; - while (n != -1) { - n = fis.read(buffer); - if (n > 0) { - digest.update(buffer, 0, n); + try (InputStream fis = Files.newInputStream(file)) { + int n = 0; + byte[] buffer = new byte[8192]; + while (n != -1) { + n = fis.read(buffer); + if (n > 0) { + digest.update(buffer, 0, n); + } } } byte[] hash = digest.digest(); @@ -313,7 +314,7 @@ public class UpdateUtils { if (shouldLaunch) { // No need to do it during shutdown: the file used will indeed be the new one logger.info("Executing: " + mainFile); - Runtime.getRuntime().exec("java -jar " + mainFile); + Runtime.getRuntime().exec(new String[]{"java", "-jar", mainFile.toString()}); } logger.info("Update installed, newer version should be executed upon relaunch"); System.exit(0);