Skip to content

Conversation

@kelmer44
Copy link

@kelmer44 kelmer44 commented Dec 3, 2025

The docs for onReceive state:

This method is called when the BroadcastReceiver is receiving an Intent broadcast.

So I am proposing to remove this qualifier. I wonder if it's possible to get this method called with a null parameter, other than clients calling this method directly, in which case I think enforcing a non-nullable parameter is all the better.

This prevents all extending kotlin classes from having to nullsafe the intent parameter before continuing.

@kelmer44 kelmer44 changed the base branch from release to main December 3, 2025 13:56
@kelmer44
Copy link
Author

kelmer44 commented Dec 3, 2025

I think i confused CI by pointing to the wrong branch 👀

@marcbaechinger marcbaechinger self-assigned this Dec 3, 2025
*/
@Override
public void onReceive(Context context, @Nullable Intent intent) {
public void onReceive(Context context, Intent intent) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can tell, if there is no @nullable or @NotNull annotation on Android framework code, then there is no nullability information available and we can't assume this is non-null.

Agreed the doc is clear about it and we can't do something sensible without an Intent. Mind adding checkNotNull(intent) when passing it further down. Sorry for being overly picky, I see we would have a NPE right after but I think I'd prefer this being consistently where we get the garbage input. Shouldn't hurt as we agree this doesn't happen.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

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.

2 participants