Skip to content

Add missing nullability annotations to Firestore. #600

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

Merged
merged 8 commits into from
Jul 12, 2019

Conversation

vkryachko
Copy link
Member

@vkryachko vkryachko commented Jul 11, 2019

Additionally remove uses of the redundant @PublicApi annotation.

@googlebot googlebot added the cla: yes Override cla label Jul 11, 2019
@vkryachko vkryachko changed the title Add proper nullability annotations to Firestore. Add missing nullability annotations to Firestore. Jul 11, 2019
Additionally remove uses of the redundant `@PublicApi` annotation.
@vkryachko vkryachko force-pushed the vk.firestore_nullability branch from 12f61ab to 1608731 Compare July 11, 2019 16:20
public Task<Void> update(
@NonNull String field, @Nullable Object value, Object... moreFieldsAndValues) {
@NonNull String field, @Nullable Object value, @NonNull Object... moreFieldsAndValues) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems incorrect. null is a valid value in here. Does the @NonNull apply to elements of the argument list or to the argument list itself?

Copy link
Member Author

Choose a reason for hiding this comment

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

It is for the argument list itself, there is no way to annotate members of the list unfortunately, so the kotlin signature will be

fun update(field: String, value: Any?, vararg moreFieldsAndValues: Any!) // note the !

Furthermore I only added this to silence the lint check, as this annotation has no effect on the above signature.

I removed these annotations now and updated the check to ignore varargs parameters.

As they don't have any effect on the resulting kotlin nullability.
@vkryachko vkryachko requested a review from rlazo July 11, 2019 17:46
@vkryachko vkryachko assigned wilhuff and unassigned vkryachko Jul 11, 2019
@vkryachko vkryachko requested a review from wilhuff July 11, 2019 17:46
@@ -17,13 +17,12 @@
import static com.google.common.base.Preconditions.checkNotNull;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not a fan of the Nullable change to androidx (but also can't say I care too strongly). Is there any good reason to prefer the android-specific version of this over the standard one other than just being consistent with the source of NonNull?

In some cases this change would be harmful. For example, we share our CustomClassMapper with the Firestore Java Server SDK. If we had properly annotated methods like this one then we really should use javax.annotation.Nullable because we can't have android dependencies on the server.

Also, the javax version of this seems to be the only Nullable I get with code completion so this is going to rot without some kind of wider announcement to go reconfigure IDEs and add a linter check or something like that to enforce the preference. Is this change really worth all that?

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right, it has no Kotlin behavior difference compared to androidx it's mostly for consistency across all SDKs, so I am ok in principle to revert firestore back to using jsr305 annotations. That said, there is nothing standard about javax annotations, they are part of a JSR that has been dormant since 2006 and is unlikely to become standard at all.

As for androidx.annotations being unusable on the server, I don't think that is true, androidx.annotations is a jar(not aar) that has no dependencies so nothing prevents them from being used on the server. Whether they have any semantic meaning for java server frameworks is a good question though.

That said, I don't feel too strongly but I have a slight preference towards androidx at least for the public APIs for consistency's sake across SDKs, and I am ok to keep javax for all internal APIs if you like. wdyt?

Copy link
Contributor

@wilhuff wilhuff Jul 11, 2019

Choose a reason for hiding this comment

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

I'd prefer some outcome where we can set it and forget it as far as Android Studio is concerned. Having different classes for public and private classes is something you can't make automatic--every code-completion import would have to choose and it seems like such a speed bump for something that has no practical value. It also seems low enough value that it's unlikely to get caught in code review.

JSR 305 was never ratified, but it seems effectively standard, especially for Google distributed software. For example, even if we standardize on the androidx one, JSR 305 will be in our classpath because that's what Guava, gRPC, and others use.

I'm more concerned that this standardization isn't going to hold automatically since doing so requires people to change their editor configuration. We need to do something to force the world to track on that: a lint check that disallows javax.annotation.Nullable would be sufficient. Absent that, we'll soon have both androidx and javax flavors in our API and otherwise which I think is worse than mixing the sources of NonNull and Nullable.

To be clear: I'm actually OK with standardizing on the androidx one throughout. The number of classes where we need to interoperate with the server is quite small so we can opt of a lint check in those cases should we implement such a check. My argument is essentially that we shouldn't standardize on androidx without such a lint check.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added lint check, note also that kotlin interop lint checks will provide automatic fix hints(in IDE) with correct(androidx) annotations.

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, I am going to disable it for now as it ripples to other SDKs, and this PR is already large enough. Will re-enable in a follow-up PR

@wilhuff wilhuff assigned vkryachko and unassigned wilhuff Jul 11, 2019
@wilhuff
Copy link
Contributor

wilhuff commented Jul 11, 2019

Aside from the question about which Nullable to use, LGTM

@vkryachko vkryachko assigned wilhuff and unassigned vkryachko Jul 11, 2019
@vkryachko vkryachko requested a review from wilhuff July 11, 2019 18:45
@wilhuff wilhuff assigned vkryachko and unassigned wilhuff Jul 11, 2019
The detector finds usages of non-androidx, non-android.support
nullability annotations and provides automatic ide fixes for such
violations.

Android Support annotations are allowed as a transitional step until
internal androidx migration is fully completed.
* disable by default(will enable in a separate PR)
* ignore kotlin source files
@vkryachko
Copy link
Member Author

/assign @wilhuff

@vkryachko vkryachko removed their assignment Jul 12, 2019
@vkryachko vkryachko self-assigned this Jul 12, 2019
@vkryachko
Copy link
Member Author

/unassign @vkryachko

@vkryachko vkryachko requested a review from rlazo July 12, 2019 15:46
Copy link
Contributor

@wilhuff wilhuff left a comment

Choose a reason for hiding this comment

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

LGTM, though I'd recommend pulling the lint check out into a separate PR altogether.

@wilhuff wilhuff assigned vkryachko and unassigned wilhuff Jul 12, 2019
@vkryachko vkryachko merged commit 1557b09 into kotlin_nullability Jul 12, 2019
vkryachko added a commit that referenced this pull request Jul 29, 2019
* Add proper nullability annotations to firebase-common. (#599)

* Add missing nullability annotations to Functions. (#601)

* Add nullability annotations, remove `@PublicApi` annotations for Storage. (#602)

* Add missing nullability annotations to Storage.

* Remove redundant `@PublicApi` annotation.

* Address review comments.

*  Add nullability annotations, remove `@PublicApi` annotations for RTDB. (#603)

* Add missing nullability annotations to RTDB.

* Remove redundant `@PublicApi` annotations.

* Update changelog.

* Add missing nullability annotations to Firestore. (#600)

* Add missing nullability annotations to Firestore.

Additionally remove uses of the redundant `@PublicApi` annotation.

* Remove varargs nullability annotations.

As they don't have any effect on the resulting kotlin nullability.

* gJF

* Add androidx.annotation lint detector.

The detector finds usages of non-androidx, non-android.support
nullability annotations and provides automatic ide fixes for such
violations.

Android Support annotations are allowed as a transitional step until
internal androidx migration is fully completed.

* Change nullability check:

* disable by default(will enable in a separate PR)
* ignore kotlin source files

* Address review comments

* Address review comments.

* ktlintFormat

* @hide abt public classes (#609)

* Fix timeouts in Functions. (#606)

This commit resolves #604 by setting both the read and call timeouts.
The connect and write timeouts are left at their default values of 10
seconds.

* Report the correct version for the RTDB (#605)

* Add missing package-info.java files for A/B Testing.

The SDK doesn't have user-visible API, so it should be correctly
annotated with javadoc's @hide.

* Add missing nullability annotations to Remote Config. (#608)
@vkryachko vkryachko deleted the vk.firestore_nullability branch September 25, 2019 20:35
@firebase firebase locked and limited conversation to collaborators Oct 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants