mirror of
https://github.com/zxing/zxing.git
synced 2024-11-09 20:44:03 -08:00
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:
parent
e17d3ae292
commit
cf52d70528
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue