From 1fde78b6f17f79126bd1304e9d4ac85a07ec9c0d Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Wed, 5 Nov 2014 13:33:13 +0100 Subject: [PATCH] java-decompiler: check for non-existent files --- .../main/decompiler/ConsoleDecompiler.java | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/org/jetbrains/java/decompiler/main/decompiler/ConsoleDecompiler.java b/src/org/jetbrains/java/decompiler/main/decompiler/ConsoleDecompiler.java index 08ec683..23b04c2 100644 --- a/src/org/jetbrains/java/decompiler/main/decompiler/ConsoleDecompiler.java +++ b/src/org/jetbrains/java/decompiler/main/decompiler/ConsoleDecompiler.java @@ -42,8 +42,8 @@ public class ConsoleDecompiler implements IBytecodeProvider, IResultSaver { } Map mapOptions = new HashMap(); - List lstSources = new ArrayList(); - List lstLibraries = new ArrayList(); + List lstSources = new ArrayList(); + List lstLibraries = new ArrayList(); boolean isOption = true; for (int i = 0; i < args.length - 1; ++i) { // last parameter - destination @@ -65,10 +65,10 @@ public class ConsoleDecompiler implements IBytecodeProvider, IResultSaver { isOption = false; if (arg.startsWith("-e=")) { - lstLibraries.add(arg.substring(3)); + addPath(lstLibraries, arg.substring(3)); } else { - lstSources.add(arg); + addPath(lstSources, arg); } } } @@ -87,16 +87,27 @@ public class ConsoleDecompiler implements IBytecodeProvider, IResultSaver { PrintStreamLogger logger = new PrintStreamLogger(System.out); ConsoleDecompiler decompiler = new ConsoleDecompiler(destination, mapOptions, logger); - for (String source : lstSources) { - decompiler.addSpace(new File(source), true); + for (File source : lstSources) { + decompiler.addSpace(source, true); } - for (String library : lstLibraries) { - decompiler.addSpace(new File(library), false); + for (File library : lstLibraries) { + decompiler.addSpace(library, false); } decompiler.decompileContext(); } + @SuppressWarnings("UseOfSystemOutOrSystemErr") + private static void addPath(List list, String path) { + File file = new File(path); + if (file.exists()) { + list.add(file); + } + else { + System.out.println("warn: missing '" + path + "', ignored"); + } + } + // ******************************************************************* // Implementation // *******************************************************************