google / google/jsinterop-generator

Add nullability annotations on generated code

Open
#25 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
85
Forks
24
PR merge metrics
No merged PRs in 30d

Description

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](https://github.com/google/closure-compiler/wiki/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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.