Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RequestQueue.cancelAll doesn't use Object.equals #152

Open
CapnSpellcheck opened this issue Mar 17, 2018 · 5 comments
Open

RequestQueue.cancelAll doesn't use Object.equals #152

CapnSpellcheck opened this issue Mar 17, 2018 · 5 comments
Milestone

Comments

@CapnSpellcheck
Copy link

public boolean apply(Request<?> request) {
                return request.getTag() == tag;
            }

Why shouldn't it use Object.equals?

@jpd236 jpd236 added this to the 1.2.0 milestone Mar 19, 2018
@jpd236
Copy link
Collaborator

jpd236 commented Mar 19, 2018

That's a very good question. Unfortunately it appears to have always been this way, and is even documented as such in the cancelAll() Javadoc, which means it's not something we can change without breaking the API contract.

The original change adding this was at https://android.googlesource.com/platform/frameworks/support/+/19a56e8495477bfd89e4c4913860fdbcb7beb504, and even internally I don't see any explanation as to why it was done this way.

We can look at adding a new API and deprecating the old one in 1.2.0. In the mean time, it's possibly to specify your own RequestFilter as follows:

cancelAll(new RequestFilter() {
    @Override
    public boolean apply(Request<?> request) {
        return Objects.equals(tag, request.getTag());
    }
});

@CapnSpellcheck
Copy link
Author

Of course. I just wanted to point this out :)

@runforprogram
Copy link

runforprogram commented Jan 7, 2019

I think it is a intentional designed, RequestManager.cancelAll is a danger method which will to cause all of requests which tag equaled be canceled. use == can be minimize side effect.think this situation has two place request a same url and use a object like a url String
,want cancel A request but not B, use == will minimal probability cause B canceled than use
Objects.equals(tag, request.getTag())

@joimxjtuse
Copy link

i agree with @runforprogram, compare '==' with String.equals(), just for efficiency.

@joebowbeer
Copy link
Contributor

In Request, the tag is defined as an opaque token.

A unit test for this functionality:

RequestQueueTest.java#L52

@jpd236 jpd236 modified the milestones: 1.2.0, 1.3.0 Feb 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants