Skip to content

Commit

Permalink
Cleanup the OkHttpStreamFetcher class.
Browse files Browse the repository at this point in the history
Updates to OkHttp 3.9.1 and removes the work around made redundant by
the new version.

Removes some unnecessary accessor class avoidance. 

Clarifies why call is volatile and the rest of the variables are not.

Fixes #2355.
  • Loading branch information
sjudd committed Dec 30, 2017
1 parent 8ed06d2 commit 642b2dc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 21 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ POM_DEVELOPER_NAME=Sam Judd
POM_DEVELOPER_EMAIL=[email protected]
ANDROID_SUPPORT_VERSION=27.0.2
VOLLEY_VERSION=1.0.0
OK_HTTP_VERSION=3.9.0
OK_HTTP_VERSION=3.9.1
ANDROID_GRADLE_VERSION=3.0.1
DAGGER_VERSION=2.11

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.bumptech.glide.integration.okhttp3;

import android.os.Build;
import android.support.annotation.NonNull;
import android.util.Log;
import com.bumptech.glide.Priority;
Expand All @@ -10,7 +9,6 @@
import com.bumptech.glide.load.model.GlideUrl;
import com.bumptech.glide.util.ContentLengthInputStream;
import com.bumptech.glide.util.Preconditions;
import com.bumptech.glide.util.Synthetic;
import java.io.IOException;
import java.io.InputStream;
import java.util.Map;
Expand All @@ -26,10 +24,12 @@ public class OkHttpStreamFetcher implements DataFetcher<InputStream>, okhttp3.Ca
private static final String TAG = "OkHttpFetcher";
private final Call.Factory client;
private final GlideUrl url;
@SuppressWarnings("WeakerAccess") @Synthetic InputStream stream;
@SuppressWarnings("WeakerAccess") @Synthetic ResponseBody responseBody;
private volatile Call call;
private InputStream stream;
private ResponseBody responseBody;
private DataCallback<? super InputStream> callback;
// call may be accessed on the main thread while the object is in use on other threads. All other
// accesses to variables may occur on different threads, but only one at a time.
private volatile Call call;

// Public API.
@SuppressWarnings("WeakerAccess")
Expand All @@ -50,21 +50,7 @@ public void loadData(@NonNull Priority priority,
this.callback = callback;

call = client.newCall(request);
if (Build.VERSION.SDK_INT != Build.VERSION_CODES.O) {
call.enqueue(this);
} else {
try {
// Calling execute instead of enqueue is a workaround for #2355, where okhttp throws a
// ClassCastException on O.
onResponse(call, call.execute());
} catch (IOException e) {
onFailure(call, e);
} catch (ClassCastException e) {
// It's not clear that this catch is necessary, the error may only occur even on O if
// enqueue is used.
onFailure(call, new IOException("Workaround for framework bug on O", e));
}
}
call.enqueue(this);
}

@Override
Expand Down

0 comments on commit 642b2dc

Please sign in to comment.