Fix some NPEs
This commit is contained in:
parent
cf6378d334
commit
a1537d2746
6 changed files with 31 additions and 20 deletions
|
@ -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());
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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())
|
||||
{
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue