Fix some sonar finings (2) (#1653)

Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2024-02-19 14:45:21 +02:00
committed by GitHub
parent 92de2d573c
commit 1845f9879f
2 changed files with 12 additions and 5 deletions

View File

@@ -111,7 +111,7 @@ public class MultiDeviceApp {
public void stopOne(@ShellOption("--id") final String controllerId) { public void stopOne(@ShellOption("--id") final String controllerId) {
final DdiController device = devices.get(controllerId); final DdiController device = devices.get(controllerId);
if (device == null) { if (device == null) {
System.out.println("ERROR: controller with id " + controllerId + " not found!"); throw new IllegalArgumentException("Controller with id " + controllerId + " not found!");
} else { } else {
device.stop(); device.stop();
} }
@@ -123,7 +123,7 @@ public class MultiDeviceApp {
@ShellOption(value = "--offset", defaultValue = "0") final int offset, @ShellOption(value = "--offset", defaultValue = "0") final int offset,
@ShellOption(value = "--count") final int count) { @ShellOption(value = "--count") final int count) {
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
startOne(String.format(prefix + "%03d", offset + i)); startOne(toId(prefix, offset + i));
} }
} }
@@ -133,8 +133,12 @@ public class MultiDeviceApp {
@ShellOption(value = "--offset", defaultValue = "0") final int offset, @ShellOption(value = "--offset", defaultValue = "0") final int offset,
@ShellOption(value = "--count") final int count) { @ShellOption(value = "--count") final int count) {
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
stopOne(String.format(prefix + "%03d", offset + i)); stopOne(toId(prefix, offset + i));
} }
} }
private static String toId(final String prefix, final int index) {
return String.format("%s%03d", prefix, index);
}
} }
} }

View File

@@ -30,6 +30,7 @@ import org.springframework.util.StringUtils;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.security.KeyManagementException; import java.security.KeyManagementException;
import java.security.KeyStoreException; import java.security.KeyStoreException;
@@ -171,10 +172,12 @@ public interface UpdateHandler {
*/ */
protected void cleanup() { protected void cleanup() {
downloads.values().forEach(path -> { downloads.values().forEach(path -> {
if (!path.toFile().delete()) { try {
Files.delete(path);
} catch (final IOException e) {
log.warn(LOG_PREFIX + "Failed to cleanup {}", log.warn(LOG_PREFIX + "Failed to cleanup {}",
ddiController.getTenantId(), ddiController.getControllerId(), ddiController.getTenantId(), ddiController.getControllerId(),
path.toFile().getAbsolutePath()); path.toFile().getAbsolutePath(), e);
} }
}); });
log.debug(LOG_PREFIX + "Cleaned up", ddiController.getTenantId(), ddiController.getControllerId()); log.debug(LOG_PREFIX + "Cleaned up", ddiController.getTenantId(), ddiController.getControllerId());