bumptech / bumptech/glide

Glide RequestOptions cannot be backward compatible

Open
#4,127 1 comment 1 reaction 0 assignees View on GitHub
enhancement
Dominant language
Java
Stars
35k
Forks
6.2k
Avg merge
1d 11h
Merged PRs (30d)
8

Description

In Class `com.bumptech.glide.RequestBuilder`,there's an important called `apply`.
In Glide version `4.8.0`,The api is
```java
public RequestBuilder apply(@NonNull RequestOptions requestOptions) {
...
}
```
But when on version `4.10.0`,The api changes to
```java
public RequestBuilder apply(@NonNull BaseRequestOptions requestOptions) {
Preconditions.checkNotNull(requestOptions);
return super.apply(requestOptions);
}

```
Despite that `RequestOptions` inherit `BaseRequestOptions`,The method signature is not the same.
So this causes a problem: WhenI use Glide 4.10.0 in my APP,but one of my dependent library use Glide 4.8.0 and use `apply` method in it's code which is already compiled to class file.It cannot find the right method.
In another library:
```java
RequestBuilder requestBuilder = Glide.with(getContext()).load(prop.asString().value());
Drawable placeHolderDrawable = getPlaceHolderDrawable();
if (placeHolderDrawable != null) {
requestBuilder = requestBuilder.apply(new RequestOptions().placeholder(placeHolderDrawable));
}
```
It causes folloiw problem:

**Stack trace / LogCat**:
```ruby
E/AndroidRuntime: FATAL EXCEPTION: main
Process: xxxxx, PID: 25279
java.lang.NoSuchMethodError: No virtual method placeholder(Landroid/graphics/drawable/Drawable;)Lcom/bumptech/glide/request/RequestOptions; in class Lcom/bumptech/glide/request/RequestOptions; or its super classes (declaration of 'com.bumptech.glide.request.RequestOptions' appears in /data/app/xxxxxx-lCBjFUgNVZ5bnGfcjjv3Ow==/base.apk)
```
If I avoid set placeholder directly,like follow code:
```java
requestBuilder = requestBuilder.apply(RequestOptions.placeholderOf(placeHolderDrawable));
```
It still crashes
**Stack trace / LogCat**:
```ruby
java.lang.NoSuchMethodError: No virtual method apply(Lcom/bumptech/glide/request/RequestOptions;)Lcom/bumptech/glide/RequestBuilder; in class Lcom/bumptech/glide/RequestBuilder; or its super classes (declaration of 'com.bumptech.glide.RequestBuilder' appears in /data/app/xxx)

```

In my suggestion, at least the `apply(RequestOptions requestOptions) ` should be add back to `RequestBuilder`.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.