Some small improvements in error handling based on exceptions observed at zxing.org
authorsrowen <srowen@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Wed, 30 Jul 2008 21:58:17 +0000 (21:58 +0000)
committersrowen <srowen@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Wed, 30 Jul 2008 21:58:17 +0000 (21:58 +0000)
git-svn-id: http://zxing.googlecode.com/svn/trunk@538 59b500cc-1b3d-0410-9834-0bbf25fbcc57

core/src/com/google/zxing/qrcode/detector/Detector.java
zxingorg/src/com/google/zxing/web/DecodeServlet.java

index f57ae58..8f06e8d 100644 (file)
@@ -74,6 +74,9 @@ public final class Detector {
     FinderPattern bottomLeft = info.getBottomLeft();
 
     float moduleSize = calculateModuleSize(topLeft, topRight, bottomLeft);
+    if (moduleSize < 1.0f) {
+      throw new ReaderException("Module size too small");
+    }
     int dimension = computeDimension(topLeft, topRight, bottomLeft, moduleSize);
     Version provisionalVersion = Version.getProvisionalVersionForDimension(dimension);
     int modulesBetweenFPCenters = provisionalVersion.getDimensionForVersion() - 7;
index 0135bb3..e5ea042 100644 (file)
@@ -58,6 +58,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStreamWriter;
 import java.io.Writer;
+import java.net.SocketException;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.UnknownHostException;
@@ -160,6 +161,14 @@ public final class DecodeServlet extends HttpServlet {
       } finally {
         is.close();
       }
+    } catch (IllegalArgumentException iae) {
+      // Thrown if hostname is bad or null
+      getRequest.abort();
+      response.sendRedirect("badurl.jspx");
+    } catch (SocketException se) {
+      // Thrown if hostname is bad or null
+      getRequest.abort();
+      response.sendRedirect("badurl.jspx");
     } catch (HttpException he) {
       getRequest.abort();
       response.sendRedirect("badurl.jspx");