Permalink
Browse files

JANDEX-6 don't treat individual file errors as fatal. Cleanup error h…

…andling a bit. Don't display usage unless there is an argument error.
  • Loading branch information...
1 parent 5581d3d commit 6e98e8d5040a59eb5f3abe7568a085b07ef58e16 @n1hility n1hility committed Aug 12, 2011
@@ -386,7 +386,7 @@ private void verifyMagic(DataInputStream stream) throws IOException {
stream.readFully(buf);
if (buf[0] != (byte)0xCA || buf[1] != (byte)0xFE || buf[2] != (byte)0xBA || buf[3] != (byte)0xBE)
- throw new RuntimeException("Invalid Magic");
+ throw new IOException("Invalid Magic");
}
@@ -57,9 +57,15 @@ public static Result createJarIndex(File jarFile, Indexer indexer, boolean modif
}
if (entry.getName().endsWith(".class")) {
- ClassInfo info = indexer.index(jar.getInputStream(entry));
- if (verbose && info != null)
- printIndexEntryInfo(info);
+ try {
+ ClassInfo info = indexer.index(jar.getInputStream(entry));
+ if (verbose && info != null)
+ printIndexEntryInfo(info);
+ } catch (Exception e) {
+ String message = e.getMessage() == null ? e.getClass().getSimpleName() : e.getMessage();
+ System.err.println("ERROR: Could not index " + entry.getName() + ": " + message); if (verbose)
+ e.printStackTrace(System.err);
+ }
}
}
@@ -56,9 +56,11 @@ public static void main(String[] args) {
private void execute(String[] args) {
+ boolean printUsage = true;
try {
parseOptions(args);
+ printUsage = false;
if (dump) {
dumpIndex(source);
return;
@@ -76,8 +78,10 @@ private void execute(String[] args) {
e.printStackTrace(System.err);
}
- System.out.println();
- printUsage();
+ if (printUsage) {
+ System.out.println();
+ printUsage();
+ }
}
}
@@ -136,9 +140,17 @@ private void scanFile(File source, Indexer indexer) throws FileNotFoundException
}
FileInputStream input = new FileInputStream(source);
- ClassInfo info = indexer.index(input);
- if (verbose)
- printIndexEntryInfo(info);
+
+ try {
+ ClassInfo info = indexer.index(input);
+ if (verbose && info != null)
+ printIndexEntryInfo(info);
+ } catch (Exception e) {
+ String message = e.getMessage() == null ? e.getClass().getSimpleName() : e.getMessage();
+ System.err.println("ERROR: Could not index " + source.getName() + ": " + message);
+ if (verbose)
+ e.printStackTrace(System.err);
+ }
return;
}

0 comments on commit 6e98e8d

Please sign in to comment.