refactor: fix several issues reported by sonar

This commit is contained in:
Skylot
2020-01-15 18:26:17 +03:00
parent 1047e751e6
commit 5e7388f686
5 changed files with 12 additions and 21 deletions
@@ -91,12 +91,7 @@ public class ConstStorage {
}
private ValueStorage getClsValues(ClassNode cls) {
ValueStorage classValues = classes.get(cls);
if (classValues == null) {
classValues = new ValueStorage();
classes.put(cls, classValues);
}
return classValues;
return classes.computeIfAbsent(cls, c -> new ValueStorage());
}
@Nullable
@@ -16,8 +16,6 @@ import org.jetbrains.annotations.Nullable;
import jadx.core.utils.exceptions.JadxRuntimeException;
import static jadx.core.utils.files.FileUtils.close;
/**
* Simple template engine
* Syntax for replace variable with value: '{{variable}}'
@@ -56,21 +54,15 @@ public class TemplateFile {
}
public String build() throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
process(out);
} finally {
close(out);
return out.toString();
}
return out.toString();
}
public void save(File outFile) throws IOException {
OutputStream out = new FileOutputStream(outFile);
try {
try (OutputStream out = new FileOutputStream(outFile)) {
process(out);
} finally {
close(out);
}
}
@@ -18,6 +18,7 @@ import java.util.List;
import java.util.Objects;
import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream;
import java.util.stream.Stream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
@@ -92,9 +93,8 @@ public class FileUtils {
}
public static void deleteDir(Path dir) {
try {
Files.walk(dir)
.sorted(Comparator.reverseOrder())
try (Stream<Path> pathStream = Files.walk(dir)) {
pathStream.sorted(Comparator.reverseOrder())
.map(Path::toFile)
.forEach(File::delete);
} catch (Exception e) {