diff --git a/annotation/compiler/test/src/test/resources/EmptyAppGlideModuleTest/GlideRequest.java b/annotation/compiler/test/src/test/resources/EmptyAppGlideModuleTest/GlideRequest.java index f6b0062749..4dfbc05b4b 100644 --- a/annotation/compiler/test/src/test/resources/EmptyAppGlideModuleTest/GlideRequest.java +++ b/annotation/compiler/test/src/test/resources/EmptyAppGlideModuleTest/GlideRequest.java @@ -484,6 +484,13 @@ public GlideRequest<TranscodeType> error(@Nullable RequestBuilder<TranscodeType> return (GlideRequest<TranscodeType>) super.error(builder); } + @Override + @NonNull + @CheckResult + public GlideRequest<TranscodeType> error(Object o) { + return (GlideRequest<TranscodeType>) super.error(o); + } + @Override @NonNull @CheckResult diff --git a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/MemoizeStaticMethod/GlideRequest.java b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/MemoizeStaticMethod/GlideRequest.java index 9c86b0097c..ecf5fa19c0 100644 --- a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/MemoizeStaticMethod/GlideRequest.java +++ b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/MemoizeStaticMethod/GlideRequest.java @@ -484,6 +484,13 @@ public GlideRequest<TranscodeType> error(@Nullable RequestBuilder<TranscodeType> return (GlideRequest<TranscodeType>) super.error(builder); } + @Override + @NonNull + @CheckResult + public GlideRequest<TranscodeType> error(Object o) { + return (GlideRequest<TranscodeType>) super.error(o); + } + @Override @NonNull @CheckResult diff --git a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtend/GlideRequest.java b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtend/GlideRequest.java index 2c886219e6..7c77d801ea 100644 --- a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtend/GlideRequest.java +++ b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtend/GlideRequest.java @@ -475,6 +475,13 @@ public GlideRequest<TranscodeType> error(@Nullable RequestBuilder<TranscodeType> return (GlideRequest<TranscodeType>) super.error(builder); } + @Override + @NonNull + @CheckResult + public GlideRequest<TranscodeType> error(Object o) { + return (GlideRequest<TranscodeType>) super.error(o); + } + @Override @NonNull @CheckResult diff --git a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtendMultipleArguments/GlideRequest.java b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtendMultipleArguments/GlideRequest.java index 1d8c2cd55d..12f34f6506 100644 --- a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtendMultipleArguments/GlideRequest.java +++ b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtendMultipleArguments/GlideRequest.java @@ -475,6 +475,13 @@ public GlideRequest<TranscodeType> error(@Nullable RequestBuilder<TranscodeType> return (GlideRequest<TranscodeType>) super.error(builder); } + @Override + @NonNull + @CheckResult + public GlideRequest<TranscodeType> error(Object o) { + return (GlideRequest<TranscodeType>) super.error(o); + } + @Override @NonNull @CheckResult diff --git a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideReplace/GlideRequest.java b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideReplace/GlideRequest.java index 8daa6e164c..891a44ef46 100644 --- a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideReplace/GlideRequest.java +++ b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideReplace/GlideRequest.java @@ -475,6 +475,13 @@ public GlideRequest<TranscodeType> error(@Nullable RequestBuilder<TranscodeType> return (GlideRequest<TranscodeType>) super.error(builder); } + @Override + @NonNull + @CheckResult + public GlideRequest<TranscodeType> error(Object o) { + return (GlideRequest<TranscodeType>) super.error(o); + } + @Override @NonNull @CheckResult diff --git a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/SkipStaticMethod/GlideRequest.java b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/SkipStaticMethod/GlideRequest.java index 9c86b0097c..ecf5fa19c0 100644 --- a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/SkipStaticMethod/GlideRequest.java +++ b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/SkipStaticMethod/GlideRequest.java @@ -484,6 +484,13 @@ public GlideRequest<TranscodeType> error(@Nullable RequestBuilder<TranscodeType> return (GlideRequest<TranscodeType>) super.error(builder); } + @Override + @NonNull + @CheckResult + public GlideRequest<TranscodeType> error(Object o) { + return (GlideRequest<TranscodeType>) super.error(o); + } + @Override @NonNull @CheckResult diff --git a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/StaticMethodName/GlideRequest.java b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/StaticMethodName/GlideRequest.java index 9c86b0097c..ecf5fa19c0 100644 --- a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/StaticMethodName/GlideRequest.java +++ b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/StaticMethodName/GlideRequest.java @@ -484,6 +484,13 @@ public GlideRequest<TranscodeType> error(@Nullable RequestBuilder<TranscodeType> return (GlideRequest<TranscodeType>) super.error(builder); } + @Override + @NonNull + @CheckResult + public GlideRequest<TranscodeType> error(Object o) { + return (GlideRequest<TranscodeType>) super.error(o); + } + @Override @NonNull @CheckResult diff --git a/annotation/compiler/test/src/test/resources/GlideExtensionWithOptionTest/GlideRequest.java b/annotation/compiler/test/src/test/resources/GlideExtensionWithOptionTest/GlideRequest.java index 100a7f974b..2013c6f6cd 100644 --- a/annotation/compiler/test/src/test/resources/GlideExtensionWithOptionTest/GlideRequest.java +++ b/annotation/compiler/test/src/test/resources/GlideExtensionWithOptionTest/GlideRequest.java @@ -484,6 +484,13 @@ public GlideRequest<TranscodeType> error(@Nullable RequestBuilder<TranscodeType> return (GlideRequest<TranscodeType>) super.error(builder); } + @Override + @NonNull + @CheckResult + public GlideRequest<TranscodeType> error(Object o) { + return (GlideRequest<TranscodeType>) super.error(o); + } + @Override @NonNull @CheckResult diff --git a/library/src/main/java/com/bumptech/glide/RequestBuilder.java b/library/src/main/java/com/bumptech/glide/RequestBuilder.java index 366478eb3a..880db65049 100644 --- a/library/src/main/java/com/bumptech/glide/RequestBuilder.java +++ b/library/src/main/java/com/bumptech/glide/RequestBuilder.java @@ -225,6 +225,43 @@ public RequestBuilder<TranscodeType> error(@Nullable RequestBuilder<TranscodeTyp return this; } + /** + * Identical to calling {@link #error(RequestBuilder)} where the {@code RequestBuilder} is the + * result of calling {@link #clone()} and removing any existing thumbnail and error {@code + * RequestBuilders} + * + * <p>You can only call this method on a {@code RequestBuilder} that has previously had {@code + * load()} called on it with a non-null model. . + * + * <p>Other than thumbnail and error {@code RequestBuilder}s, which are removed, all other options + * are retained from the primary request. However, <b>order matters!</b> Any options applied after + * this method is called will not be applied to the error {@code RequestBuilder}. We should move + */ + @NonNull + @CheckResult + public RequestBuilder<TranscodeType> error(Object model) { + if (model == null) { + return error((RequestBuilder<TranscodeType>) null); + } + if (this.model == null) { + throw new IllegalArgumentException( + "Call this method after calling #load() with a non-null" + " model."); + } + if (!this.model.getClass().isAssignableFrom(model.getClass())) { + throw new IllegalArgumentException( + "You can only call #error(Object) with the same type of" + + " model that you provided to #load(). If you need to load a different type, use the" + + " somewhat more verbose #error(RequestBuilder) method instead of this shortcut"); + } + return error(cloneWithNullErrorAndThumbnail().load(model)); + } + + private RequestBuilder<TranscodeType> cloneWithNullErrorAndThumbnail() { + return clone() + .error((RequestBuilder<TranscodeType>) null) + .thumbnail((RequestBuilder<TranscodeType>) null); + } + /** * Loads and displays the resource retrieved by the given thumbnail request if it finishes before * this request. Best used for loading thumbnail resources that are smaller and will be loaded