Fix NPE in cancelling network calls

Summary:
Issue reported here
https://github.com/facebook/react-native/issues/7755#issuecomment-222950463

Converting int to Integer explicitly and not cancelling the call more than once
should fix it.

Reviewed By: bestander

Differential Revision: D3371238

fbshipit-source-id: cb00663b4ca19a788bd27b971b6447cc0788a818
This commit is contained in:
Andrei Coman 2016-06-03 02:58:36 -07:00 committed by Facebook Github Bot 8
parent 8fe58849a5
commit 5de1151bdd
2 changed files with 3 additions and 1 deletions

View File

@ -24,11 +24,13 @@ public class OkHttpCallUtil {
for (Call call : client.dispatcher().queuedCalls()) {
if (tag.equals(call.request().tag())) {
call.cancel();
return;
}
}
for (Call call : client.dispatcher().runningCalls()) {
if (tag.equals(call.request().tag())) {
call.cancel();
return;
}
}
}

View File

@ -384,7 +384,7 @@ public final class NetworkingModule extends ReactContextBaseJavaModule {
new GuardedAsyncTask<Void, Void>(getReactApplicationContext()) {
@Override
protected void doInBackgroundGuarded(Void... params) {
OkHttpCallUtil.cancelTag(mClient, requestId);
OkHttpCallUtil.cancelTag(mClient, Integer.valueOf(requestId));
}
}.execute();
}