Repository: square/retrofit
Issue: Cloning a call leads to callback being invoked off the main thread

I have to retry a call in the callback after it failed. As mentioned in various places, you can do so by cloning the Call<T> and enqueuing (or executing) it again. Problem is, that cloned callback is not invoked on the main thread (which I need for doing UI stuff).
I played around with other/new callbacks, starting a completely new call, etc. Only when I clone the call the callback is invoked off the main thread.

Using Retrofit 2.0.1

Was confimred by at least one other user:
[Stackoverflow topic](http://stackoverflow.com/questions/36407237/cloning-a-call-leads-to-callback-being-called-off-the-main-thread)

``` java
public static abstract class MyCallback<T> implements Callback<T> {
    @Override
    public void onResponse(Call<T> call, retrofit2.Response<T> response) {
        Timber.d("is this the main thread %b", Looper.myLooper() == Looper.getMainLooper());
        if (response.isSuccessful()) {
            //success handling
        } else {
            if (response.code() == 406) {
                // remedy reason for failure
                call.clone().enqueue(MyCallback.this);
            }
        }
    }
    @Override
    public void onFailure(Call<T> call, Throwable t) {
        Timber.e("onFailure %s", t.getMessage());
    }
}
```

Gives:

```
is this the main thread true
is this the main thread false
is this the main thread false
is this the main thread false
is this the main thread false
[looping]
```


Issue comments:

Pull request review comments:

Patch that resolved the issue:
diff --git a/retrofit/src/main/java/retrofit2/ExecutorCallAdapterFactory.java b/retrofit/src/main/java/retrofit2/ExecutorCallAdapterFactory.java
index 95ecbf4b7e..0c44243c6f 100644
--- a/retrofit/src/main/java/retrofit2/ExecutorCallAdapterFactory.java
+++ b/retrofit/src/main/java/retrofit2/ExecutorCallAdapterFactory.java
@@ -58,23 +58,23 @@ static final class ExecutorCallbackCall<T> implements Call<T> {
       if (callback == null) throw new NullPointerException("callback == null");
 
       delegate.enqueue(new Callback<T>() {
-        @Override public void onResponse(final Call<T> call, final Response<T> response) {
+        @Override public void onResponse(Call<T> call, final Response<T> response) {
           callbackExecutor.execute(new Runnable() {
             @Override public void run() {
               if (delegate.isCanceled()) {
                 // Emulate OkHttp's behavior of throwing/delivering an IOException on cancellation.
-                callback.onFailure(call, new IOException("Canceled"));
+                callback.onFailure(ExecutorCallbackCall.this, new IOException("Canceled"));
               } else {
-                callback.onResponse(call, response);
+                callback.onResponse(ExecutorCallbackCall.this, response);
               }
             }
           });
         }
 
-        @Override public void onFailure(final Call<T> call, final Throwable t) {
+        @Override public void onFailure(Call<T> call, final Throwable t) {
           callbackExecutor.execute(new Runnable() {
             @Override public void run() {
-              callback.onFailure(call, t);
+              callback.onFailure(ExecutorCallbackCall.this, t);
             }
           });
         }


Test patch:
diff --git a/retrofit/src/test/java/retrofit2/ExecutorCallAdapterFactoryTest.java b/retrofit/src/test/java/retrofit2/ExecutorCallAdapterFactoryTest.java
index ba45b5fe67..24b8710529 100644
--- a/retrofit/src/test/java/retrofit2/ExecutorCallAdapterFactoryTest.java
+++ b/retrofit/src/test/java/retrofit2/ExecutorCallAdapterFactoryTest.java
@@ -94,7 +94,7 @@ public final class ExecutorCallAdapterFactoryTest {
     Call<String> call = (Call<String>) adapter.adapt(originalCall);
     call.enqueue(callback);
     verify(callbackExecutor).execute(any(Runnable.class));
-    verify(callback).onResponse(originalCall, response);
+    verify(callback).onResponse(call, response);
   }
 
   @Test public void adaptedCallEnqueueUsesExecutorForFailureCallback() {
@@ -111,7 +111,7 @@ public final class ExecutorCallAdapterFactoryTest {
     call.enqueue(callback);
     verify(callbackExecutor).execute(any(Runnable.class));
     verifyNoMoreInteractions(callbackExecutor);
-    verify(callback).onFailure(originalCall, throwable);
+    verify(callback).onFailure(call, throwable);
     verifyNoMoreInteractions(callback);
   }