Fix pretty clear bug on Code 128 and 39 readers: reject empty barcodes as a false...
authorsrowen <srowen@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Wed, 18 Jun 2008 21:56:30 +0000 (21:56 +0000)
committersrowen <srowen@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Wed, 18 Jun 2008 21:56:30 +0000 (21:56 +0000)
git-svn-id: http://zxing.googlecode.com/svn/trunk@440 59b500cc-1b3d-0410-9834-0bbf25fbcc57

core/src/com/google/zxing/oned/Code128Reader.java
core/src/com/google/zxing/oned/Code39Reader.java
core/test/src/com/google/zxing/common/FalsePositivesBlackBoxTestCase.java

index eec326e..1fc430c 100644 (file)
@@ -405,6 +405,12 @@ public final class Code128Reader extends AbstractOneDReader {
     }
 
     String resultString = result.toString();
+
+    if (resultString.length() == 0) {
+      // Almost surely a false positive
+      throw new ReaderException("Empty barcode found; assuming a false positive");
+    }
+
     float left = (float) (startPatternInfo[1] + startPatternInfo[0]) / 2.0f;
     float right = (float) (nextStart + lastStart) / 2.0f;
     return new Result(
index 2811312..12f36b1 100644 (file)
@@ -138,6 +138,12 @@ public final class Code39Reader extends AbstractOneDReader {
     if (extendedMode) {
       resultString = decodeExtended(resultString);
     }
+
+    if (resultString.length() == 0) {
+      // Almost surely a false positive
+      throw new ReaderException("Empty barcode found; assuming a false positive");
+    }
+
     float left = (float) (start[1] + start[0]) / 2.0f;
     float right = (float) (nextStart + lastStart) / 2.0f;
     return new Result(
index a623d11..d078c15 100644 (file)
@@ -42,6 +42,7 @@ public final class FalsePositivesBlackBoxTestCase extends AbstractBlackBoxTestCa
     super(new File("test/data/blackbox/falsepositives"), new MultiFormatReader(), null);
   }
 
+  @Override
   public void testBlackBox() throws IOException {
     File[] imageFiles = getImageFiles();
     int falsePositives = 0;
@@ -51,6 +52,9 @@ public final class FalsePositivesBlackBoxTestCase extends AbstractBlackBoxTestCa
       // Try all four rotations, since many of the test images don't have a notion of up, and we
       // want to be as robust as possible.
       BufferedImage image = ImageIO.read(testImage);
+      if (image == null) {
+        throw new IOException("Could not read image: " + testImage);
+      }
       for (int x = 0; x < 4; x++) {
         if (!checkForFalsePositives(image, x * 90.0f)) {
           falsePositives++;