ballerina-platform / ballerina-lang

The Ballerina Programming Language
https://ballerina.io/
Apache License 2.0
3.68k stars 751 forks source link

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

Open Shadow-Devil opened 1 month ago

Shadow-Devil commented 1 month ago

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

Shadow-Devil commented 1 month ago

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