Fix some NPEs

This commit is contained in:
Nico Mexis 2021-07-18 22:38:53 +02:00
parent cf6378d334
commit a1537d2746
No known key found for this signature in database
GPG key ID: 27D6E17CE092AB78
6 changed files with 31 additions and 20 deletions

View file

@ -17,6 +17,7 @@ import the.bytecode.club.bytecodeviewer.BytecodeViewer;
import the.bytecode.club.bytecodeviewer.Configuration;
import the.bytecode.club.bytecodeviewer.Constants;
import the.bytecode.club.bytecodeviewer.api.ExceptionUI;
import the.bytecode.club.bytecodeviewer.util.MiscUtils;
import the.bytecode.club.bytecodeviewer.util.ZipUtils;
import static the.bytecode.club.bytecodeviewer.Constants.*;
@ -267,7 +268,7 @@ public class Boot {
public static void setState(String s)
{
if(screen != null)
if (screen != null)
screen.setTitle(s);
}
@ -295,7 +296,7 @@ public class Boot {
public static void populateLibsDirectory() {
File libsDir = libsDir();
if (libsDir.exists())
for (File f : Objects.requireNonNull(libsDir.listFiles())) {
for (File f : MiscUtils.listFiles(libsDir)) {
libsList.add(f.getName());
libsFileList.add(f.getAbsolutePath());
}
@ -450,14 +451,14 @@ public class Boot {
setState("Bytecode Viewer Boot Screen - Checking Enjarify...");
System.out.println("Checking enjarify");
File enjarifyZip = null;
for (File f : Objects.requireNonNull(new File(Constants.libsDirectory).listFiles())) {
for (File f : MiscUtils.listFiles(new File(Constants.libsDirectory))) {
if (f.getName().toLowerCase().startsWith("enjarify-")) {
Constants.enjarifyVersion = f.getName().split("-")[1].split("\\.")[0];
enjarifyZip = f;
}
}
for (File f : Objects.requireNonNull(new File(getBCVDirectory()).listFiles())) {
for (File f : MiscUtils.listFiles(new File(getBCVDirectory()))) {
if (f.getName().toLowerCase().startsWith("enjarify_") && !f.getName().split("_")[1].split("\\.")[0].equals(Constants.enjarifyVersion)) {
setState("Bytecode Viewer Boot Screen - Removing Outdated " + f.getName() + "...");
System.out.println("Removing oudated " + f.getName());
@ -493,7 +494,7 @@ public class Boot {
System.out.println("Checking krakatau");
File krakatauZip = null;
for (File f : Objects.requireNonNull(new File(Constants.libsDirectory).listFiles())) {
for (File f : MiscUtils.listFiles(new File(Constants.libsDirectory))) {
if (f.getName().toLowerCase().startsWith("krakatau-")) {
//System.out.println(f.getName());
Constants.krakatauVersion = f.getName().split("-")[1].split("\\.")[0];
@ -501,7 +502,7 @@ public class Boot {
}
}
for (File f : Objects.requireNonNull(new File(getBCVDirectory()).listFiles())) {
for (File f : MiscUtils.listFiles(new File(getBCVDirectory()))) {
if (f.getName().toLowerCase().startsWith("krakatau_") && !f.getName().split("_")[1].split("\\.")[0].equals(Constants.krakatauVersion)) {
setState("Bytecode Viewer Boot Screen - Removing Outdated " + f.getName() + "...");
System.out.println("Removing oudated " + f.getName());

View file

@ -141,7 +141,7 @@ public class CFRDecompiler extends InternalDecompiler
File file = new File(fuckery);
if (file.exists())
return findFile(Objects.requireNonNull(file.listFiles()));
return findFile(MiscUtils.listFiles(file));
return CFR + " " + ERROR + "! " + ExceptionUI.SEND_STACKTRACE_TO +
nl + nl + TranslatedStrings.SUGGESTED_FIX_DECOMPILER_ERROR +
@ -162,7 +162,7 @@ public class CFRDecompiler extends InternalDecompiler
public String findFile(File[] fA) {
for (File f : fA) {
if (f.isDirectory())
return findFile(Objects.requireNonNull(f.listFiles()));
return findFile(MiscUtils.listFiles(f));
else {
String s;
try {
@ -331,7 +331,7 @@ public class CFRDecompiler extends InternalDecompiler
res = zout;
while (!queue.isEmpty()) {
directory = queue.pop();
for (File kid : Objects.requireNonNull(directory.listFiles())) {
for (File kid : MiscUtils.listFiles(directory)) {
String name = base.relativize(kid.toURI()).getPath();
if (kid.isDirectory()) {
queue.push(kid);

View file

@ -86,7 +86,7 @@ public class JADXDecompiler extends InternalDecompiler
tempClass.delete();
if (fuckery.exists())
return findFile(Objects.requireNonNull(fuckery.listFiles()));
return findFile(MiscUtils.listFiles(fuckery));
if(exception.isEmpty())
exception = "Decompiled source file not found!";
@ -113,7 +113,7 @@ public class JADXDecompiler extends InternalDecompiler
public String findFile(File[] fA) {
for (File f : fA) {
if (f.isDirectory())
return findFile(Objects.requireNonNull(f.listFiles()));
return findFile(MiscUtils.listFiles(f));
else {
String s;
try {

View file

@ -11,6 +11,7 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Objects;
import the.bytecode.club.bytecodeviewer.util.MiscUtils;
import static the.bytecode.club.bytecodeviewer.Constants.*;
@ -319,7 +320,7 @@ public class ExternalResources
*/
public String findLibrary(String nameContains)
{
for (File f : Objects.requireNonNull(new File(libsDirectory).listFiles()))
for (File f : MiscUtils.listFiles(new File(libsDirectory)))
if (f.getName().contains(nameContains))
return f.getAbsolutePath();
@ -331,7 +332,7 @@ public class ExternalResources
*/
public File findFile(File basePath, String extension)
{
for(File f : basePath.listFiles())
for(File f : MiscUtils.listFiles(basePath))
{
if(f.isDirectory())
{

View file

@ -40,13 +40,12 @@ public class DirectoryResourceImporter implements Importer
for (int i = 0; i < totalFiles.size(); i++)
{
File child = totalFiles.get(i);
if (child.listFiles() != null)
for (File rocket : Objects.requireNonNull(child.listFiles()))
if (!totalFiles.contains(rocket))
{
totalFiles.add(rocket);
added = true;
}
for (File rocket : MiscUtils.listFiles(child))
if (!totalFiles.contains(rocket))
{
totalFiles.add(rocket);
added = true;
}
}
if (!added)

View file

@ -295,4 +295,14 @@ public class MiscUtils
baos.close();
return baos.toByteArray();
}
public static File[] listFiles(File file) {
if (file == null)
return new File[0];
File[] list = file.listFiles();
if (list != null)
return list;
return new File[0];
}
}