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

Translate nullability/optional typescript properties and methods into @Nullable / @NotNull annotations in the Java CDK #6026

Closed
2 tasks
ivoanjo opened this issue Jan 30, 2020 · 3 comments
Assignees
Labels
effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. jsii This issue originates in jsii, or this feature must be implemented in jsii. language/java Related to Java bindings

Comments

@ivoanjo
Copy link
Contributor

ivoanjo commented Jan 30, 2020

Please add the @Nullable / @NotNull annotations as appropriate when generating the Java CDK bindings from typescript constructs that are marked as optional or as not optional.

Use Case

While Java has no native way of saying "this can be null" / "this is not expected to be null", the @Nullable / @NotNull annotations are a way of doing that, enabling

  • Developers working on IDEs such as IntelliJ to get helpful messages when they don't check for null
  • Tools such as FindBugs to find problematic usages in a codebase

and even better in my case

Proposed Solution

Add the annotations when generating Java code.

Other

There's also a feature request asking for this in the AWS Java SDK, which unfortunately has not been addressed yet.

  • 👋 I may be able to implement this feature request
  • ⚠️ This feature might incur a breaking change

This is a 🚀 Feature Request

@ivoanjo ivoanjo added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Jan 30, 2020
@ivoanjo ivoanjo changed the title Translate typescript properties and methods into @Nullable / @NotNull annotations in the Java CDK Translate nullability/optional typescript properties and methods into @Nullable / @NotNull annotations in the Java CDK Jan 30, 2020
@SomayaB SomayaB added the language/java Related to Java bindings label Jan 30, 2020
@RomainMuller
Copy link
Contributor

RomainMuller commented Jan 31, 2020

We used to have code annotated with @Nullable, but it was pulled due to the lack of a clear standardization around those annotations.

I was however not aware of the Kotlin behavior you describe.

I would tend to favor the JSR-305 annotations.

@RomainMuller RomainMuller added effort/small Small work item – less than a day of effort and removed needs-triage This issue or PR still needs to be triaged. labels Jan 31, 2020
@ivoanjo
Copy link
Contributor Author

ivoanjo commented Jan 31, 2020

We used to have code annotated with @Nullable, but it was pulled due to the lack of a clear standardization around those annotations.

Oh, that's interesting, didn't notice it.

Yeah, for Kotlin it would definitely be very useful -- and the Kotlin compiler supports JSR-305 so that would work great for us.

So even though it's not standard for those tools, all of them support JSR-305 so targetting that would be enough to work with all of them :)

@RomainMuller
Copy link
Contributor

In fact, steering away from JSR-305 (it's dormant and causes issues with Java 11 due to it's using the javax.* namespace in violation of the JVM license agreement).

Since the main upsides here is facilitating Kotlin interoperability, I'm rooting for the JetBrains annotations at this point.

RomainMuller added a commit to aws/jsii that referenced this issue Feb 3, 2020
This commit annotates values (parameters, properties, and method return
values) with the JetBrains annotations associated to the use-case.

Implements aws/aws-cdk#6026
mergify bot pushed a commit to aws/jsii that referenced this issue Feb 3, 2020
* feat(java): annotate nullability

This commit annotates values (parameters, properties, and method return
values) with the JetBrains annotations associated to the use-case.

Implements aws/aws-cdk#6026

* de-duplicate code
@RomainMuller RomainMuller added the jsii This issue originates in jsii, or this feature must be implemented in jsii. label Feb 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. jsii This issue originates in jsii, or this feature must be implemented in jsii. language/java Related to Java bindings
Projects
None yet
Development

No branches or pull requests

3 participants