Skip to content

Add nullability annotations to ContentSet methods. #650 #651

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

lemonboston
Copy link
Contributor

No description provided.

@@ -336,13 +340,13 @@ private ContentValues ensureAfter()
values = new ContentValues();
mAfterContentValues = values;
// also create mAfterKeys
mAfterKeys = new HashSet<String>();
mAfterKeys = new HashSet<>();
Copy link
Owner

Choose a reason for hiding this comment

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

Please remove mAfterKeys while you're at it. It was only a workaround for the absence of ContentValues.keySet() on Android 2.x. Since we don't support Android 2 any more you can remove it in most places and replace by mAfterContentValues.keySet() where it's being read.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I've removed mAfterKeys.

@@ -544,7 +553,7 @@ else if (mBeforeContentValues != null && mBeforeContentValues.get(key) != null)
}


public void addOnChangeListener(OnContentChangeListener listener, String key, boolean notify)
public void addOnChangeListener(@NonNull OnContentChangeListener listener, @Nullable String key, boolean notify)
Copy link
Owner

Choose a reason for hiding this comment

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

I think it doesn't make sense to add a listener for changes to a null key. So key should be @NonNull.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are usages of these methods with null key, so that's why I used Nullable. I've checked now and null actually has a special usage here, see:

/**
* A {@link Map} for the {@link OnContentChangeListener}s. A listener registers for a specific key in a content set or for <code>null</code> to e notified
* of full reloads.
*/
private final Map<String, Set<OnContentChangeListener>> mOnChangeListeners = new HashMap<String, Set<OnContentChangeListener>>();

So now I've just added some javadoc to the methods about the key parameter.
Let me know if you'd prefer it to be changed somehow.

Copy link
Owner

Choose a reason for hiding this comment

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

I right, I forgot about that. Passing null will cause the listener to be called for any update on any key. Did you check if we actually use that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, they are called with null key from ViewTaskFragment and EditTaskFragment.

@@ -563,7 +572,7 @@ public void addOnChangeListener(OnContentChangeListener listener, String key, bo
}


public void removeOnChangeListener(OnContentChangeListener listener, String key)
public void removeOnChangeListener(@NonNull OnContentChangeListener listener, @Nullable String key)
Copy link
Owner

Choose a reason for hiding this comment

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

same here, key is @NonNull.

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