glide icon indicating copy to clipboard operation
glide copied to clipboard

Request: add NonNull annotation for the Bitmap in RequestListener.onResourceReady

Open AndroidDeveloperLB opened this issue 3 years ago • 2 comments
trafficstars

I'm using this version of Glide:

implementation 'com.github.bumptech.glide:glide:4.13.2'

And this command to load some bitmap:

Glide.with(context).asBitmap().load(imgFile).addListener(listener).apply(RequestOptions.centerInsideTransform().skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE)).submit(screenWidth, screenHeight)

For the listener, I've noticed that there are no nullable annotations, so I get these function callbacks:

override fun onLoadFailed(e: GlideException?, model: Any?, target: Target<Bitmap>?, isFirstResource: Boolean): Boolean {

override fun onResourceReady(resource: Bitmap?, model: Any?, target: Target<Bitmap>?, dataSource: DataSource?, isFirstResource: Boolean): Boolean {

I think it's safe to say that at least for onResourceReady , the resource shouldn't be null, because of the docs about it ("resource – The resource that was loaded for the target.") , and because otherwise we have onLoadFailed:

Please add this annotation there, and if possible, also annotations for the rest.

AndroidDeveloperLB avatar Aug 15 '22 14:08 AndroidDeveloperLB

Please feel free to send a pull request

sjudd avatar Aug 26 '22 15:08 sjudd

@sjudd OK here: https://github.com/bumptech/glide/pull/4884

But I think there are more similar cases, such as ResourceCallback.

Also, for some reason I can't build the project. I get this error:

studio64_YONeXBVC6E.zip


warnings found and -Werror specified

FAILURE: Build completed with 3 failures.

1: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':annotation:compileJava'.
> Compilation failed; see the compiler error output for details.

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
==============================================================================

2: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':third_party:disklrucache:compileReleaseJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
==============================================================================

3: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':third_party:disklrucache:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
==============================================================================

* Get more help at https://help.gradle.org

BUILD FAILED in 28s

AndroidDeveloperLB avatar Aug 27 '22 17:08 AndroidDeveloperLB

@sjudd I would like to pick up this issue

mayorjay avatar Dec 06 '22 19:12 mayorjay

Hey, @sjudd @AndroidDeveloperLB it's Mudssir Ahmed and I'm starting to work on this issue, If possible you can assign it to me.

MudssirAhmed avatar Jan 29 '23 13:01 MudssirAhmed

@MudssirAhmed I have no way to change it. I don't have the credentials, or something.

AndroidDeveloperLB avatar Jan 29 '23 13:01 AndroidDeveloperLB

This ended up being done in 60b567e5feec70ba810a663e56a10d837f26c56c

sjudd avatar Aug 20 '23 18:08 sjudd

Thank you guys. It's a good practice to run the code-analyze feature to find places that need to have nullability annotations.

AndroidDeveloperLB avatar Aug 20 '23 19:08 AndroidDeveloperLB