Skip to content

Commit b174344

Browse files
author
Davey Fong
committed
Fixed: Exception black/white list in RetryHandler not checked against child classes like ConnectTimeoutException, causing connection hang when the destination is unreachable.
1 parent c0a31d3 commit b174344

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/com/loopj/android/http/RetryHandler.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@
2828
import java.net.SocketException;
2929
import java.net.UnknownHostException;
3030
import java.util.HashSet;
31+
import java.util.Iterator;
3132

3233
import javax.net.ssl.SSLHandshakeException;
3334

3435
import org.apache.http.NoHttpResponseException;
35-
import org.apache.http.client.methods.HttpUriRequest;
3636
import org.apache.http.client.HttpRequestRetryHandler;
37+
import org.apache.http.client.methods.HttpUriRequest;
3738
import org.apache.http.protocol.ExecutionContext;
3839
import org.apache.http.protocol.HttpContext;
3940

@@ -73,10 +74,10 @@ public boolean retryRequest(IOException exception, int executionCount, HttpConte
7374
if(executionCount > maxRetries) {
7475
// Do not retry if over max retry count
7576
retry = false;
76-
} else if (exceptionBlacklist.contains(exception.getClass())) {
77+
} else if (isInList(exceptionBlacklist, exception)) {
7778
// immediately cancel retry if the error is blacklisted
7879
retry = false;
79-
} else if (exceptionWhitelist.contains(exception.getClass())) {
80+
} else if (isInList(exceptionWhitelist, exception)) {
8081
// immediately retry if error is whitelisted
8182
retry = true;
8283
} else if (!sent) {
@@ -99,4 +100,14 @@ public boolean retryRequest(IOException exception, int executionCount, HttpConte
99100

100101
return retry;
101102
}
103+
104+
protected boolean isInList(HashSet<Class<?>> list, Throwable error) {
105+
Iterator<Class<?>> itr = list.iterator();
106+
while (itr.hasNext()) {
107+
if (itr.next().isInstance(error)) {
108+
return true;
109+
}
110+
}
111+
return false;
112+
}
102113
}

0 commit comments

Comments
 (0)