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 #1217

Open
matthewadams opened this issue Aug 22, 2024 · 4 comments
Open

Add nullability annotations #1217

matthewadams opened this issue Aug 22, 2024 · 4 comments
Assignees
Labels
proposal Enhancement idea or proposal

Comments

@matthewadams
Copy link

Proposed change

Please annotate the API, including return types and parameters, with @javax.annotations.NonNull or @javax.annotations.Nullable as appropriate so that users of the API know what can and can't be null.

Use case

My use case is when using jnats from kotlin, but it applies to any user of jnats. For example, I discovered that io.nats.client.api.KeyValueEntry has a method

public byte[] getValue() {
  return value;
}

that allows for the returned byte[] to be null. Kotlin builds nullability into the type system for compile-time checking, and if Java APIs include these annotations, the kotlin compiler can inform the developer better about nullability.

Contribution

No response

@matthewadams matthewadams added the proposal Enhancement idea or proposal label Aug 22, 2024
@scottf
Copy link
Contributor

scottf commented Aug 22, 2024

@matthewadams We are currently looking at how we can improve integration with Kotlin, and this will make the list.

@MauriceVanVeen
Copy link
Member

MauriceVanVeen commented Aug 23, 2024

Have an example of using JetBrains' annotations here: 869012b

Tried out javax and jakarta annotations for @NotNull as well, but those didn't seem to be recognized.

Without the @NotNull annotation you need to technically handle the case where entry.operation == null, even if it's not possible to be
image

Adding JetBrains' @NotNull solves that.
image

Could be an option to use those.

@MauriceVanVeen
Copy link
Member

An alternative that works as well: org.checkerframework:checker-qual using @NonNull.

@cbasener
Copy link

cbasener commented Sep 4, 2024

Maybe this is also an option?
https://jspecify.dev/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal Enhancement idea or proposal
Projects
None yet
Development

No branches or pull requests

4 participants