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

fix NPE in deliverResponse() method of Request's subclass. #64

Merged
merged 2 commits into from
Aug 1, 2017
Merged

fix NPE in deliverResponse() method of Request's subclass. #64

merged 2 commits into from
Aug 1, 2017

Conversation

xyhuangjinfu
Copy link
Contributor

No description provided.

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed, please reply here (e.g. I signed it!) and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If your company signed a CLA, they designated a Point of Contact who decides which employees are authorized to participate. You may need to contact the Point of Contact for your company and ask to be added to the group of authorized contributors. If you don't know who your Point of Contact is, direct the project maintainer to go/cla#troubleshoot.
  • In order to pass this check, please resolve this problem and have the pull request author add another comment and the bot will run again.

@xyhuangjinfu
Copy link
Contributor Author

xyhuangjinfu commented Jul 30, 2017 via email

@googlebot
Copy link

CLAs look good, thanks!

@jpd236
Copy link
Collaborator

jpd236 commented Jul 31, 2017

Thank you for sending this.

Do you actually have a use case where you want to pass in a null listener? If not, I think it would be friendlier to developers if we instead had the constructors for these classes check whether the listener is null and throw an IllegalArgumentException if they are. You have three choices for what to do when a developer passes in a null listener:

  1. Do nothing. Code will crash with a mysterious NullPointerException and the developer will think it's a Volley bug. That's not good :)
  2. Guard against the NPE to avoid the crash. No crash is good, but now responses will be silently dropped. If the developer has a bug where they're accidentally passing null, they won't know about it and will need to debug more deeply. Better than crashing at random, but still not ideal.
  3. Crash loudly with an appropriate error message (e.g. throw new IllegalArgumentException("ResponseListener must not be null")) at the time the error occurs. This means the developer will see the error quite clearly at the moment it occurs and will be empowered to fix it.

Since a developer who really didn't care about the response could always pass in a listener that does nothing, that feels safest to me. (And it seems very unlikely this would happen because you should really care about the responses coming back successfully, I'd think).

@xyhuangjinfu
Copy link
Contributor Author

Thanks for response.
I thinked a lot, the third solution are indeed best. but I just consider that this can be processed like the way to process the mErrorListener field in Request class. mErrorListener field are processed like the second solution.

@jpd236
Copy link
Collaborator

jpd236 commented Aug 1, 2017

Thanks, I didn't think to check how mErrorListener was handled in the Request class.

I'll take this for now as an improvement and have filed #65 to consider cleaning up the two listeners together.

@jpd236 jpd236 merged commit d40b75f into google:master Aug 1, 2017
@xyhuangjinfu
Copy link
Contributor Author

I find that in ClearCacheRequest class, it not need whether a mListener or a mErrorListener.

@jpd236
Copy link
Collaborator

jpd236 commented Aug 1, 2017

Noted at #65, thanks.

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

Successfully merging this pull request may close these issues.

3 participants