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

Add nullability annotations on generated code #25

Open
realityforge opened this issue Mar 23, 2019 · 1 comment
Open

Add nullability annotations on generated code #25

realityforge opened this issue Mar 23, 2019 · 1 comment

Comments

@realityforge
Copy link
Contributor

Closure externs already have the concept of nullable and non-nullable values. Some types are implicitly nullable and some are implicitly nonnull although these can be explicitly overridden. See Types-in-the-Closure-Type-System for further details.

When translating the externs into java code this nullability is not modelled in the java code. There seems to be @JsNonNull and @JsNullable annotations that may be able to be used. Another possibility is to use @javax.annotation.Nonnull and @javax.annotation.Nullable which would integrate much better with existing java tools. Alternatively they could both be applied where appropriate.

Adding the javax.annotation annotation almost instantly improves the experience when editing in an IDE like IDEA which will highlight where the developer has failed to check for null or conversely, checks for null without cause.

The one disadvantage is that if the upstream closure compiler externs are incorrectly annotated (and some of them are), it will confuse the developer and it may force us to fix the upstream externs.

In the future I plan to tackle this issue but no set timeline

@tbroyer
Copy link

tbroyer commented Mar 23, 2019

javax.annotation shouldn't be used nowadays. org.checkerframework.checker.nullness.qual.Nullable is a better replacement (or possibly org.jetbrains.annotations.Nullable from org.jetbrains:annotations, or edu.umd.cs.findbugs.annotations.Nullable from com.github.spotbugs:spotbugs-annotations)

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

2 participants