Work around Android NPE bug in HttpURLConnection.connect()

git-svn-id: https://zxing.googlecode.com/svn/trunk@2416 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
srowen 2012-09-26 10:34:31 +00:00
parent e17d3ae292
commit cf52d70528

View file

@ -95,7 +95,12 @@ public final class HttpHelper {
connection.setRequestProperty("Accept-Charset", "utf-8,*");
connection.setRequestProperty("User-Agent", "ZXing (Android)");
try {
connection.connect();
try {
connection.connect();
} catch (NullPointerException npe) {
// this is an Android bug: http://code.google.com/p/android/issues/detail?id=16895
throw new IOException(npe);
}
if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
throw new IOException("Bad HTTP response: " + connection.getResponseCode());
}
@ -152,7 +157,12 @@ public final class HttpHelper {
connection.setRequestMethod("HEAD");
connection.setRequestProperty("User-Agent", "ZXing (Android)");
try {
connection.connect();
try {
connection.connect();
} catch (NullPointerException npe) {
// this is an Android bug: http://code.google.com/p/android/issues/detail?id=16895
throw new IOException(npe);
}
switch (connection.getResponseCode()) {
case HttpURLConnection.HTTP_MULT_CHOICE:
case HttpURLConnection.HTTP_MOVED_PERM: