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

[Improvement]: Add jetbrains annotations to the classpath dependencies for @NotNull and @Nullable annotations #43386

Open
Shadow-Devil opened this issue Sep 12, 2024 · 1 comment · May be fixed by #43393
Labels
needTriage The issue has to be inspected and labeled manually Type/Improvement

Comments

@Shadow-Devil
Copy link
Contributor

Description

There is already some small usage of this dependency in the jballerina-unit-test module (here and here) but it is only via a transitive dependency of the kotlin std lib.

+--- project :ballerina-lang
|    +--- project :central-client
|    |    +--- com.squareup.okhttp3:okhttp -> 3.14.0
|    |    |    \--- com.squareup.okio:okio:1.17.2 -> 3.4.0
|    |    |         \--- com.squareup.okio:okio-jvm:3.4.0
|    |    |              +--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.0
|    |    |              |    +--- org.jetbrains.kotlin:kotlin-stdlib:1.8.0
|    |    |              |    |    \--- org.jetbrains:annotations:13.0

It would be great to add this dependency directly to the javaProject.gradle compileOnly scope, so it can be used everywhere (without adding any runtime overhead or increasing the distribution size).

There are other options for @Nullable annotations, e.g.

but since the JetBrains annotations are already used I think these should be adopted.
This would help will NPEs since nullable values can be annotated and therefore better documented.
Also IntelliJ and Spotbugs use these annotations in static analysis.

Describe your problem(s)

There is currently no standard defined to document nullable values in the project.

Describe your solution(s)

Add this dependency to the compileOnly scope of the javaProject.gradle file.

Related area

-> Other Area

Related issue(s) (optional)

No response

Suggested label(s) (optional)

No response

Suggested assignee(s) (optional)

No response

@ballerina-bot ballerina-bot added the needTriage The issue has to be inspected and labeled manually label Sep 12, 2024
@Shadow-Devil
Copy link
Contributor Author

This would also enable developers to write @Contracts which describes how methods behave to different inputs.
Examples:

  • @Contract("null -> null") if you provide a null to this method it will return null
  • @Contract("-> new") this method will create a new object and return it
  • @Contract("null -> fail") this method will throw an exception if you provide a null value.
  • @Contract("true -> fail") a typical assertFalse method which throws an exception if true is passed to it

@Shadow-Devil Shadow-Devil linked a pull request Sep 13, 2024 that will close this issue
13 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needTriage The issue has to be inspected and labeled manually Type/Improvement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants