Added the ability to track who is throwing exceptions and how often in the core libra...
authordswitkin <dswitkin@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Sun, 13 Dec 2009 17:10:02 +0000 (17:10 +0000)
committerdswitkin <dswitkin@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Sun, 13 Dec 2009 17:10:02 +0000 (17:10 +0000)
git-svn-id: http://zxing.googlecode.com/svn/trunk@1155 59b500cc-1b3d-0410-9834-0bbf25fbcc57

core/src/com/google/zxing/ReaderException.java
javase/src/com/google/zxing/client/j2se/CommandLineRunner.java

index 0d8a3d5..4e6a90f 100644 (file)
@@ -36,14 +36,58 @@ public final class ReaderException extends Exception {
 
   private static final ReaderException instance = new ReaderException();
 
 
   private static final ReaderException instance = new ReaderException();
 
+  // EXCEPTION TRACKING SUPPORT
+  // Identifies who is throwing exceptions and how often. To use:
+  //
+  // 1. Uncomment these lines and the code below which uses them.
+  // 2. Uncomment the two corresponding lines in j2se/CommandLineRunner.decode()
+  // 3. Change core to build as Java 1.5 temporarily
+//  private static int exceptionCount = 0;
+//  private static Map<String,Integer> throwers = new HashMap<String,Integer>(32);
+
   private ReaderException() {
     // do nothing
   }
 
   public static ReaderException getInstance() {
   private ReaderException() {
     // do nothing
   }
 
   public static ReaderException getInstance() {
+//    Exception e = new Exception();
+//    // Take the stack frame before this one.
+//    StackTraceElement stack = e.getStackTrace()[1];
+//    String key = stack.getClassName() + "." + stack.getMethodName() + "(), line " +
+//        stack.getLineNumber();
+//    if (throwers.containsKey(key)) {
+//      Integer value = throwers.get(key);
+//      value++;
+//      throwers.put(key, value);
+//    } else {
+//      throwers.put(key, 1);
+//    }
+//    exceptionCount++;
+
     return instance;
   }
 
     return instance;
   }
 
+//  public static int getExceptionCountAndReset() {
+//    int temp = exceptionCount;
+//    exceptionCount = 0;
+//    return temp;
+//  }
+//
+//  public static String getThrowersAndReset() {
+//    StringBuilder builder = new StringBuilder(1024);
+//    Object[] keys = throwers.keySet().toArray();
+//    for (int x = 0; x < keys.length; x++) {
+//      String key = (String) keys[x];
+//      Integer value = throwers.get(key);
+//      builder.append(key);
+//      builder.append(": ");
+//      builder.append(value);
+//      builder.append("\n");
+//    }
+//    throwers.clear();
+//    return builder.toString();
+//  }
+
   // Prevent stack traces from being taken
   // srowen says: huh, my IDE is saying this is not an override. native methods can't be overridden?
   // This, at least, does not hurt. Because we use a singleton pattern here, it doesn't matter anyhow.
   // Prevent stack traces from being taken
   // srowen says: huh, my IDE is saying this is not an override. native methods can't be overridden?
   // This, at least, does not hurt. Because we use a singleton pattern here, it doesn't matter anyhow.
index a607cd6..f9ccf7c 100644 (file)
@@ -200,6 +200,10 @@ public final class CommandLineRunner {
     } catch (ReaderException e) {
       System.out.println(uri.toString() + ": No barcode found");
       return null;
     } catch (ReaderException e) {
       System.out.println(uri.toString() + ": No barcode found");
       return null;
+    } finally {
+      // Uncomment these lines when turning on exception tracking in ReaderException.
+      //System.out.println("Threw " + ReaderException.getExceptionCountAndReset() + " exceptions");
+      //System.out.println("Throwers:\n" + ReaderException.getThrowersAndReset());
     }
   }
 
     }
   }