Work around Android NPE observed in the wild

git-svn-id: https://zxing.googlecode.com/svn/trunk@2451 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
srowen 2012-10-07 11:16:08 +00:00
parent 4c4ebbe0c5
commit db7afc66b6

View file

@ -110,8 +110,16 @@ public final class HttpHelper {
Log.w(TAG, "Bad URI? " + uri); Log.w(TAG, "Bad URI? " + uri);
throw new IOException(iae); throw new IOException(iae);
} }
if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) { int responseCode;
throw new IOException("Bad HTTP response: " + connection.getResponseCode()); try {
responseCode = connection.getResponseCode();
} catch (NullPointerException npe) {
// this is maybe this Android bug: http://code.google.com/p/android/issues/detail?id=15554
Log.w(TAG, "Bad URI? " + uri);
throw new IOException(npe);
}
if (responseCode != HttpURLConnection.HTTP_OK) {
throw new IOException("Bad HTTP response: " + responseCode);
} }
Log.i(TAG, "Consuming " + uri); Log.i(TAG, "Consuming " + uri);
return consume(connection, maxChars); return consume(connection, maxChars);